Number Input
A field that allows user input of numeric values.
Anatomy
<NumberInput.Root>
<NumberInput.Label />
<NumberInput.Scrubber />
<NumberInput.Control>
<NumberInput.Input />
<NumberInput.IncrementTrigger />
<NumberInput.DecrementTrigger />
</NumberInput.Control>
</NumberInput.Root>
Examples
Min and Max
Set min and max to limit the value. The input clamps the value to that range.
To allow values outside the min/max range, set
clampValueOnBlurtofalse.
Precision
To round to fixed decimals, pass Intl.NumberFormatOptions like maximumFractionDigits or minimumFractionDigits to
formatOptions.
Scrubbing
Render NumberInput.Scrubber to change the value by dragging. It uses the Pointer Lock API to track movement and
renders a virtual cursor.
Mouse Wheel
Set allowMouseWheel to increment or decrement with the mouse wheel.
Formatting
Pass Intl.NumberFormatOptions like style and currency to formatOptions.
Field
Field wires up the label, helper text, error text and their ARIA attributes.
Root Provider
Use RootProvider with the useNumberInput hook to access the state and methods from outside the component.
Guides
Scrubber
NumberInput.Scrubber is a <div> users drag to change the value. It shows a custom cursor while scrubbing and uses
the Pointer Lock API.
Note: Browsers may show a notification when pointer lock activates. The scrubber is disabled in Safari to prevent layout shifts.
Controlled
Keep the controlled value as a string, not a number. This matters most with formatOptions for currency or locales.
const [value, setValue] = useState('0')
<NumberInput.Root value={value} onValueChange={(details) => setValue(details.value)}>
{/* ... */}
</NumberInput.Root>
Converting to numbers breaks locale formats with different decimal and thousands separators (e.g., 1.523,30 vs
1,523.30). Strings keep the formatting intact.
To submit a numeric value, add a hidden input that reads value from NumberInput.Context:
<NumberInput.Root value={value} onValueChange={(details) => setValue(details.value)}>
<NumberInput.Input />
<NumberInput.Context>
{(context) => <input type="hidden" name="amount" value={context.value ?? ''} />}
</NumberInput.Context>
</NumberInput.Root>
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
allowMouseWheel | booleanWhether to allow mouse wheel to change the value | |
allowOutOfRange | false | booleanWhether a typed value can stay outside the min/max range instead of being clamped on blur or Enter. The value is then reported as invalid. Stepping always stays within the range. |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
defaultValue | numberThe initial value when rendered. Use when you don't need to control the value. | |
disabled | booleanWhether the number input is disabled. | |
focusInputOnChange | true | booleanWhether to focus input when the value changes |
form | stringThe associate form of the input element. | |
formatOptions | NumberFormatOptionsThe options to pass to the `Intl.NumberFormat` constructor | |
id | stringThe unique identifier of the machine. | |
ids | Partial<{
root: string
label: string
input: string
incrementTrigger: string
decrementTrigger: string
scrubber: string
scrubberCursor: string
hiddenInput: string
}>The ids of the elements in the number input. Useful for composition. | |
inputMode | InputModeHints at the type of data that might be entered by the user. It also determines the type of keyboard shown to the user on mobile devices. Defaults to `"text"` on iPhone when negatives are allowed, otherwise `"decimal"`. | |
invalid | booleanWhether the number input value is invalid. | |
largeStep | step * 10 | numberStep value when Shift key is held (large increments). |
locale | 'en-US' | stringThe current locale. Based on the BCP 47 definition. |
max | numberThe maximum value of the number input | |
min | numberThe minimum value of the number input | |
name | stringThe name attribute of the number input. Useful for form submission. | |
onFocusChange | (details: FocusChangeDetails) => voidFunction invoked when the number input is focused | |
onValueChange | (details: ValueChangeDetails) => voidFunction invoked when the value changes | |
onValueCommit | (details: ValueChangeDetails) => voidFunction invoked when the value settles: the input is blurred or `Enter` is pressed, a stepper or scrub gesture ends, or a key or wheel step completes. | |
onValueInvalid | (details: ValueInvalidDetails) => voidFunction invoked when the value overflows or underflows the min/max range | |
pattern | '-?[0-9]*(.[0-9]+)?' | stringThe pattern used to check the <input> element's value against |
readOnly | booleanWhether the number input is readonly | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NumberInputRootState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
required | booleanWhether the number input is required | |
scrubberDirection | 'horizontal' | 'horizontal' | 'vertical'The direction of scrubbing. |
scrubberPixelSensitivity | 2 | numberHow many pixels the pointer must move to change the value by one step. Higher values mean more precise control. Lower values mean more sensitivity. |
scrubberTeleportDistance | numberDistance in pixels before the virtual cursor wraps around. When not set, the viewport bounds are used (default behavior). | |
smallStep | step * 0.1 | numberStep value when Alt/Option key is held (fine control). |
snapOnStep | false | booleanWhether values snap to step multiples when scrubbing. |
spinOnPress | true | booleanWhether to spin the value when the increment/decrement button is pressed |
step | 1 | numberThe amount to increment or decrement the value by |
translations | IntlTranslationsSpecifies the localized strings that identifies the accessibility elements and their states | |
value | numberThe controlled value. Use `null` for an empty input. |
| Attribute | Description |
|---|---|
[data-number-input-root] | <uid> |
[data-disabled] | Present when disabled |
[data-focus] | Present when focused |
[data-invalid] | Present when invalid |
[data-scrubbing] |
Control
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-number-input-control] | <uid> |
[data-focus] | Present when focused |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-scrubbing] |
DecrementTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | type ONLY_FOR_FORMAT =
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NumberInputDecrementTriggerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-number-input-decrement-trigger] | <uid> |
[data-disabled] | Present when disabled |
[data-scrubbing] |
IncrementTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | type ONLY_FOR_FORMAT =
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NumberInputIncrementTriggerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-number-input-increment-trigger] | <uid> |
[data-disabled] | Present when disabled |
[data-scrubbing] |
Input
Defines the <input> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NumberInputInputState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-number-input-input] | <uid> |
[data-invalid] | Present when invalid |
[data-disabled] | Present when disabled |
[data-scrubbing] |
Label
Defines the <label> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-number-input-label] | <uid> |
[data-disabled] | Present when disabled |
[data-focus] | Present when focused |
[data-invalid] | Present when invalid |
[data-required] | Present when required |
[data-scrubbing] |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UseNumberInputReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | type ONLY_FOR_FORMAT =
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NumberInputRootProviderState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Scrubber
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-number-input-scrubber] | <uid> |
[data-disabled] | Present when disabled |
[data-scrubbing] |
| CSS Variable | Description |
|---|---|
--scrubber-x | The scrubber x value for the Scrubber |
--scrubber-y | The scrubber y value for the Scrubber |
--scrubber-scale | The scrubber scale value for the Scrubber |
ValueText
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-number-input-value-text] | <uid> |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-focus] | Present when focused |
[data-scrubbing] |
Context
API
| Property | Type |
|---|---|
focused | booleanWhether the input is focused. |
scrubbing | booleanWhether the input is being scrubbed. |
invalid | booleanWhether the input is invalid. |
empty | booleanWhether the input value is empty. |
value | number | nullThe number, or `null` when the input is empty. |
formattedValue | stringThe value as shown in the input. |
setValue | (value: number) => voidFunction to set the value of the input. |
clearValue | VoidFunctionFunction to clear the value of the input. |
increment | VoidFunctionFunction to increment the value of the input by the step. |
decrement | VoidFunctionFunction to decrement the value of the input by the step. |
setToMax | VoidFunctionFunction to set the value of the input to the max. |
setToMin | VoidFunctionFunction to set the value of the input to the min. |
focus | VoidFunctionFunction to focus the input. |
getRootState | () => RootStateReturns the state of the root. |
getInputState | () => InputStateReturns the state of the input. |
getDecrementTriggerState | () => DecrementTriggerStateReturns the state of the decrement trigger. |
getIncrementTriggerState | () => IncrementTriggerStateReturns the state of the increment trigger. |
Accessibility
Complies with the Spinbutton WAI-ARIA design pattern.
Keyboard Support
| Key | Description |
|---|---|
ArrowUp | Increments the value of the number input by a predefined step. |
ArrowDown | Decrements the value of the number input by a predefined step. |
Shift + ArrowUp | Increments the value of the number input by the `largeStep` amount. |
Shift + ArrowDown | Decrements the value of the number input by the `largeStep` amount. |
Alt + ArrowUp | Increments the value of the number input by the `smallStep` amount. |
Alt + ArrowDown | Decrements the value of the number input by the `smallStep` amount. |
Home | Sets the value of the number input to its minimum allowed value. |
End | Sets the value of the number input to its maximum allowed value. |
Enter | Submits the value entered in the number input. |