Number Group

A number input with its buttons, as Base UI's NumberField: typed and read in the locale (currencies, percents, units), stepped with the keyboard, held buttons, the wheel or by dragging its label, and a Signal Forms control. In a scField, as any input.

FormsExperimental

Usage

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScLabel,  ScNumberDecrement,  ScNumberGroup,  ScNumberIncrement,  ScNumberInput,  ScNumberScrubArea,} from '@semantic-components/ui';import { SiMinusIcon, SiPlusIcon } from '@semantic-icons/lucide-icons';
@Component({  selector: 'app-number-group-usage-demo',  imports: [    ScLabel,    ScField,    ScNumberScrubArea,    ScNumberGroup,    ScNumberDecrement,    ScNumberInput,    ScNumberIncrement,    SiMinusIcon,    SiPlusIcon,  ],  template: `    <div scField class="w-40">      <div scNumberScrubArea [pixelSensitivity]="10">        <label scLabel>Quantity</label>      </div>      <div scNumberGroup [(value)]="quantity" [min]="1" [max]="10">        <button scNumberDecrement>          <svg siMinusIcon></svg>          <span class="sr-only">Decrease quantity</span>        </button>        <input scNumberInput />        <button scNumberIncrement>          <svg siPlusIcon></svg>          <span class="sr-only">Increase quantity</span>        </button>      </div>    </div>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class NumberGroupUsageDemo {  private readonly quantity = signal<number | null>(1);}

Anatomy

A scField holds the label, the group and the descriptions. The group joins the input and its buttons and holds the value — a Signal Forms control. A scrub area round the label changes the value by dragging: it reaches the group through the field.

import {  ScField, ScNumberGroup, ScNumberInput,  ScNumberIncrement, ScNumberDecrement,  ScNumberScrubArea, ScNumberScrubAreaCursor, ScLabel,} from '@semantic-components/ui';
<div scField>  <div scNumberScrubArea>  <!-- optional: drag to change -->    <label scLabel>…</label>    <span scNumberScrubAreaCursor>…</span>  </div>  <div scNumberGroup [formField]="…">    <button scNumberDecrement>…</button>    <input scNumberInput />    <button scNumberIncrement>…</button>  </div></div>

Examples

Value and committed value

Value
10
Committed
10
import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScFrame,  ScLabel,  ScNumberDecrement,  ScNumberGroup,  ScNumberIncrement,  ScNumberInput,  ScNumberScrubArea,

Scrubbing

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScLabel,  ScNumberDecrement,  ScNumberGroup,  ScNumberIncrement,  ScNumberInput,  ScNumberScrubArea,  ScNumberScrubAreaCursor,

Steps, snapping and the wheel

Type 12, then press ↑: it snaps to 15.

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScKbd,  ScLabel,  ScNumberDecrement,  ScNumberGroup,  ScNumberIncrement,  ScNumberInput,  ScNumberScrubArea,

Stacked buttons

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScLabel,  ScNumberDecrement,  ScNumberGroup,  ScNumberIncrement,  ScNumberInput,} from '@semantic-components/ui';import {

Quantities

Between 1 and 8.

Up to 8.

Up to 4.

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScFieldDescription,  ScLabel,  ScNumberDecrement,  ScNumberGroup,  ScNumberIncrement,  ScNumberInput,} from '@semantic-components/ui';

Currency in another locale

Value: 1234.5

import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScFrame,  ScLabel,  ScNumberDecrement,  ScNumberGroup,  ScNumberIncrement,  ScNumberInput,  ScNumberScrubArea,

Signal Forms

{
  "value": 10,
  "valid": true,
  "touched": false,
  "ordered": null
}
import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import { FormField, form, max, min, required } from '@angular/forms/signals';import {  ScButton,  ScField,  ScFieldErrors,  ScFrame,  ScLabel,  ScNumberDecrement,  ScNumberGroup,

Disabled and read-only

import { Component, ViewEncapsulation } from '@angular/core';import {  ScField,  ScLabel,  ScNumberDecrement,  ScNumberGroup,  ScNumberIncrement,  ScNumberInput,  ScNumberScrubArea,} from '@semantic-components/ui';

Without a scrub area

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScNumberDecrement,  ScNumberGroup,  ScNumberIncrement,  ScNumberInput,} from '@semantic-components/ui';import { SiMinusIcon, SiPlusIcon } from '@semantic-icons/lucide-icons';

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScLabel,  ScNumberDecrement,  ScNumberGroup,  ScNumberIncrement,  ScNumberInput,  ScNumberScrubArea,

API reference

Each part takes class, merged over the style (cn: a later class wins). The label, descriptions and errors are the scField's the group is in, as for any input.

PartSelectorDescription
ScNumberGroupdiv[scNumberGroup] The input and its buttons, joined, one focus ring round them; it holds the value and its rules: [(value)] (a number, or null); min, max; step (1), smallStep (0.1, with Alt), largeStep (10, with Shift or Page Up / Down); snapOnStep; format (Intl.NumberFormat options: currencies, percents, units; in LOCALE_ID); allowWheelScrub; disabled. A Signal Forms control ([formField]: min, max, required, disabled from the schema); with a name, a hidden input submits the plain number. variant: 'split' (decrement, input, increment, as written) or 'stacked' (the input, then increment over decrement). exportAs scNumberGroup.
ScNumberInputinput[scNumberInput] The text field, a spin button: typed text read in the locale, written formatted on Enter or leaving, within the bounds. ↑ ↓ step, Page Up / Down by largeStep, Home / End to the min / max. Named by the field’s label.
ScNumberIncrement, ScNumberDecrementbutton[scNumberIncrement], button[scNumberDecrement] Step up / down, repeatedly while held; not in the Tab order, the new value announced; aria-disabled at the bound. Write the icon and name it.
ScNumberScrubArea[scNumberScrubArea] Drag on it to change the value: round the label, in the same scField as the group (it reaches it through the field). orientation ('horizontal'), one step per pixelSensitivity (2) pixels; with a mouse, the pointer is locked.
ScNumberScrubAreaCursor[scNumberScrubAreaCursor] Stands in for the locked pointer while scrubbing: write an icon in it, inside the scrub area.