Forms
Number input
Bounded numbers with step buttons.
Usage
A spinbutton that looks like our Input, with − and + buttons, min, max and step. The value is a real number (or null when the field is empty), never a string.
5 seats at $12 = $60 per month.
When to use
- Small counts and amounts people nudge up and down: seats, quantity, guests, discounts.
- Money and percentages, where the shown text (€1,249.00, 15%) differs from the stored number.
Not for: phone numbers, postcodes, card numbers or ids (use a text input), or picking a value from a wide range (use a slider).
Currency and locale
format is number, currency or percent, shown with Intl.NumberFormat in the given locale. The typed text is parsed on blur (and on Enter) in the same locale: group separators, symbols and a trailing % are ignored. Unreadable text is dropped and the previous value returns. Pass locale explicitly so server and client render the same text.
Type any amount, such as 1,249.5. It is formatted when you leave the field.
Stored value: 1249
Percent values are fractions, like Intl: 0.15 shows as 15%, so one percentage point is step={0.01}. Mouse-wheel stepping is opt-in with allowWheel, and only works while the field is focused.
One step is one percentage point. Scroll over the field while it is focused to change it.
Buttons and sizes
Buttons sit inside the field, are attached as segments, or are hidden with none. A button disables itself at its bound. Hold a button to repeat; the longer you hold, the faster and bigger the steps.
API
NumberInput
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue | number | null | null | Controlled / initial value. null is an empty field. |
| onValueChange | (value: number | null) => void | — | Called when a value is committed: step, key, wheel, blur or Enter. Not on each keystroke. |
| min / max | number | — | Bounds. Values are clamped; the buttons disable at them. |
| step / largeStep | number | 1 / step × 10 | Arrow and button step; PageUp / PageDown step. |
| format | 'number' | 'currency' | 'percent' | 'number' | How the value is displayed and parsed. |
| locale / currency | string | — | BCP 47 tag and ISO 4217 code ("en-IE", "EUR"). |
| minimumFractionDigits / maximumFractionDigits | number | — | Override the decimals shown. |
| controls | 'inside' | 'attached' | 'none' | 'inside' | Where the − and + buttons go. |
| allowWheel | boolean | false | Change the value with the wheel while focused. |
| holdToRepeat | boolean | true | Repeat and accelerate while a button is held. |
| size | 'sm' | 'md' | 'lg' | 'md' | Height 32 / 36 / 44px. |
| incrementLabel / decrementLabel | string | 'Increase' / 'Decrease' | Accessible names of the buttons. |
| name | string | — | Submits the raw number through a hidden input. |
| groupClassName | string | — | Class for the surrounding group; className goes on the input. |
| ...props | InputHTMLAttributes | — | Forwarded to the input (placeholder, disabled, readOnly, aria-*), including ref. |
Keyboard
| Key | Action |
|---|---|
| Up / Down | Increase or decrease by one step. Shift makes it ten steps. |
| PageUp / PageDown | Increase or decrease by ten steps (or largeStep). |
| Home / End | Jump to min / max, when they are set. |
| Enter | Commits the typed text. In a form it still submits. |
| Tab | Commits on leaving. The − and + buttons are not tab stops. |
Accessibility
- The input has
role="spinbutton"witharia-valuenow,aria-valuemin,aria-valuemaxandaria-valuetext(the formatted text). - Keyboard users and screen readers use the arrow keys; the buttons are for pointers and stay out of the tab order but remain clickable by assistive technology.
- Inside a Field the id, aria-describedby, aria-invalid, required and disabled state are wired automatically.
- On touch devices the text is 16px, so iOS Safari does not zoom on focus.
Motion
- Border and ring transition over 150ms; inside buttons press to .94 on the snappy spring.
- The number changes instantly: it is the information, so it is not animated.
- Reduced motion drops the press scale; hover tints stay on fine pointers only.