Inputs
NumberInput
From 1 to 20
Value: 3
When to use
- You need numeric input with
min,max,steporIntl.NumberFormatformatting. - A form needs a field with an accessible name and increment/decrement buttons.
When not to use
- For a free-text identifier or code, use
TextControl; for a phone number there isPhoneInput. - For continuous selection on a visual scale, use
Slider/RangeSlider.
Minimal example
<NumberInput
label="Publication limit"
value={limit}
onChange={setLimit}
min={0}
max={100}
step={1}
/>Public API
valueandonChangeare required; the valuenullmeans an empty input.labelis required and ties the name to the inner React Aria input; theFormFieldwrapper does not replace it.formatOptionsis passed toIntl.NumberFormat;invalidonly shows the invalid state; the validation rule stays with the consumer. Inside aFormFieldwitherrorthe flag arrives from the form on its own; an explicitinvalid={false}clears it.shellClassNameapplies to the border,classNameto the root NumberField.
Currency is a NumberInput, not a separate component
CurrencyInput does not exist in the kit, and this is a decision
(ADR-0024), not a gap.
A currency field comes down to formatOptions:
<NumberInput
label="Amount"
value={amount}
onChange={setAmount}
formatOptions={{ style: "currency", currency: "RUB" }}
/>Intl.NumberFormat inside react-aria formats the currency, parses the input and
takes the grouping separators and the decimal separator from the locale: in ru-RU
that is 1 234,56 ₽, in en-US — $1,234.56. A separate component would be a
wrapper with no logic of its own, like a ThemeSwitcher over Segmented.
Percentages and units of measure are handled by Intl.NumberFormat too:
<NumberInput label="Discount" formatOptions={{ style: "percent" }} />
<NumberInput label="Weight" formatOptions={{ style: "unit", unit: "kilogram" }} />A mask is no help here: MaskedInput would hard-wire the separators, and in
another locale the field would show the format of another locale.
Accessibility and forms
- The increment/decrement buttons get their names from
labelautomatically. - Do not turn emptiness into zero: it changes the meaning of the data.
- Source:
src/components/inputs/NumberInput.tsx; checks —tests/number-input.test.tsx.
TypeScript types
NumberInputProps
Prop
Type