Number Field
A numeric input supporting stepping, locale formatting, nullable values, and label scrubbing.
A numeric input with keyboard and button stepping, localized number formatting, optional empty values, and horizontal label scrubbing.
Preview
Section titled “Preview” Web Components React Vue Vue 2
Loading interactive preview… The article and source are ready to read. Interactive controls will appear here when ready.
Installation
Section titled “Installation”Available starting in 0.3.0-rc.1 and later releases.
Compose Root, Label, Input, Control, Increment, and Decrement:
- Editing and stepping:
Rootmanages thenumber | nullvalue.Inputprovides a spinbutton text editor that preserves incomplete drafts while typing and commits a valid number (or restores the last accepted value) on blur orEnter.Increment/DecrementandArrowUp/ArrowDownstep bystep(Shiftmultiplies by 10);Home/Endjump to bounds when set, or keep native cursor movement when unbounded. Passvaluefor controlled mode. - Formatting and IME:
localeandformatOptionssupport decimal, currency, and percent formatting and parsing (including localized separators, digits, and signs) without altering underlying numeric precision. Invalid formatting options setformatInvalidand fall back to ungrouped decimals. Active IME composition pauses parsing, commits, stepping, and scrubbing while preserving composition text across locale changes. - Nullable values: Explicit
nullrepresents an empty value, andvalue={null}stays controlled. SetallowEmptyto requestnullwhen clearing and committing the input. ReadgetValue(): number | nullandemptyfor exact state (the compatibility numericvaluereadout reflects the number whenemptyisfalse, while events andField/Formalways receivenull). Stepping fromnullinitializes at snapped0within bounds. - Label scrubbing: Enable
scrubto adjust the value continuously by draggingLabel.scrubSteps(default100) sets the number of steps per initial label width, anddirection="rtl"reverses horizontal drag direction. Releasing after a change commits once; canceling restores the uncontrolled start value while keeping normal text selection in the input. - Form integration: Use
Controlinstead ofInputinsideField/FormFieldto integrateFieldLabel,required, numeric validation, serialization, and reset. UseLabelwith standaloneInput.
| Prop | Type | Default |
|---|---|---|
value | number null | — |
defaultValue | number null | 0 |
min | number null | 0 |
max | number null | 100 |
step | number | 1 |
snapToStep | boolean | true |
disabled | boolean | false |
readOnly | boolean | false |
required | boolean | false |
ariaLabel | string | '' |
name | string | '' |
allowEmpty | boolean | false |
locale | string | — |
formatOptions | NumberFieldFormatOptions | — |
scrub | boolean | false |
scrubSteps | number | 100 |
direction | 'ltr' 'rtl' | 'ltr' |
Label, Input, Control, Increment, and Decrement add no props of their own.
- Bounds and snapping: Omitted
min/maxdefault to0/100; passnullto remove a bound. SettingsnapToStep={false}preserves finite initial and edited values whilestepstill controls increments. - Required resolution:
requiredcombines with any enclosingFieldrequirement and applies to both the native editor and accessibility attributes.