Number Field
A numeric input element with increment and decrement buttons, and a scrub area.
Usage guidelines
- Form controls must have an accessible name: It can be created using a
<label>element or theFieldcomponent. See the forms guide.
Anatomy
Import the component and assemble its parts:
Examples
Controlling the input text
value holds the parsed number, so it can’t represent text that isn’t a number yet.
Typing -1.5 passes through - and -1., neither of which parses, and both leave value untouched.
To drive those intermediate states, control the raw text with inputValue, defaultInputValue, and onInputValueChange.
It’s independent of value, so both can be controlled at once:
The text is never formatted or clamped on the way in, so any string is allowed.
onInputValueChange reports the text two ways. Typing, clearing, and pasting report the raw string verbatim — input-change, input-clear, and input-paste carry exactly what the user produced, with no formatting applied. Blur, stepping, and the 'none' reason instead propose formatted text, the last of these after an external value, locale, or format change.
Mirroring every call back into inputValue reproduces the uncontrolled behavior. Every call must be answered: mirror it, or refuse it with eventDetails.cancel(). Refusing a formatted proposal keeps your own text, and refusing an input-change call vetoes the keystroke outright rather than preserving anything. Ignoring a call is neither — the text stays as it was while the rest of the change goes through, so the field can end up showing one number and reporting another.
Intermediate states are transient by design. Blur reconciles any text that isn’t a number back to value under 'input-blur', whether the user typed it or you set it yourself — so a '-' you installed programmatically is proposed away as soon as the field is focused and left, even with no edits in between. Refuse the 'input-blur' call to keep it.
API reference
Root
Groups all parts of the number field and manages its state.
Renders a <div> element.
namestring—
- Name
- Description
Identifies the field when a form is submitted.
- Type
defaultValuenumber—
- Name
- Description
The uncontrolled value of the field when it’s initially rendered.
To render a controlled number field, use the
valueprop instead.- Type
valuenumber | null—
- Name
- Description
The raw numeric value of the field.
- Type
onValueChangefunction—
- Name
- Description
Callback fired when the number value changes.
The
eventDetails.reasonindicates what triggered the change:'input-change'for parseable typing or programmatic text updates'input-clear'when the field becomes empty'input-blur'when formatting (and clamping, if enabled) occurs on blur'input-paste'for paste interactions'keyboard'for arrow-key/Home/End stepping (typing digits uses'input-change'/'input-clear')'increment-press'/'decrement-press'for button presses on the increment and decrement controls'wheel'for wheel-based scrubbing'scrub'for scrub area drags
- Type
onValueCommittedfunction—
- Name
- Description
Callback function that is fired when the value is committed. It runs later than
onValueChange, when:- The input is blurred after typing a value.
- The pointer is released after scrubbing or pressing the increment/decrement buttons.
It runs simultaneously with
onValueChangewhen interacting with the keyboard or the mouse wheel.Warning: This is a generic event not a change event.
- Type
defaultInputValuestring—
- Description
The uncontrolled raw text of the input element when it’s initially rendered. Defaults to the formatted
value.To render a controlled input, use the
inputValueprop instead.- Type
inputValuestring—
- Name
- Description
The raw text shown in the input element.
Unlike
value, this can hold strings that aren’t parseable as a number yet, such as'-'or'.', which lets the field be driven through intermediate states while typing. The text is never formatted or clamped on the way in. It is reported back throughonInputValueChangeeither verbatim, as the user types, clears, or pastes, or formatted, on blur, when stepping, and after an externalvalue,locale, orformatchange. Each call must either be mirrored back into this prop or refused witheventDetails.cancel(); ignoring one keeps the old text while the rest of the change goes through.- Type
onInputValueChangefunction—
- Description
Callback fired when the raw text shown in the input element changes.
This fires for the same reasons as
onValueChange, plus the cases that leave the numeric value untouched, such as typing a lone'-', and with'none'when the formatted text is refreshed after an externalvalue,locale, orformatchange. Text that isn’t a number is reconciled back tovalueon blur, under'input-blur', however it got there.- Type
allowOutOfRangebooleanfalse
- Name
- Description
When true, direct text entry may be outside the
min/maxrange without clamping, so native range underflow/overflow validation can occur. Step-based interactions (keyboard arrows, buttons, wheel, scrub) still clamp.- Type
- Default
false
formstring—
- Name
- Description
Identifies the form that owns the hidden input. Useful when the number field is rendered outside the form.
- Type
localeIntl.LocalesArgument—
- Name
- Description
The locale of the input element. Defaults to the user’s runtime locale.
- Type
snapOnStepbooleanfalse
- Name
- Description
Whether the value should snap to the nearest step when incrementing or decrementing.
- Type
- Default
false
stepnumber | 'any'1
- Name
- Description
Amount to increment and decrement with the buttons and arrow keys, or to scrub with pointer movement in the scrub area. To always enable step validation on form submission, specify the
minprop explicitly in conjunction with this prop. Specifystep="any"to always disable step validation; interactive stepping then uses a base amount of1, while the alt and shift keys still step bysmallStepandlargeStep.- Type
- Default
1
smallStepnumber0.1
- Name
- Description
The small step value of the input element when incrementing while the alt key is held. Snaps to multiples of this value when
snapOnStepis enabled.- Type
- Default
0.1
largeStepnumber10
- Name
- Description
The large step value of the input element when incrementing while the shift key is held. Snaps to multiples of this value when
snapOnStepis enabled.- Type
- Default
10
minnumber—
- Name
- Description
The minimum value of the input element.
- Type
maxnumber—
- Name
- Description
The maximum value of the input element.
- Type
allowWheelScrubbooleanfalse
- Name
- Description
Whether to allow the user to scrub the input value with the mouse wheel while focused and hovering over the input.
- Type
- Default
false
formatIntl.NumberFormatOptions—
- Name
- Description
Options to format the input value.
- Type
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
- Default
false
readOnlybooleanfalse
- Name
- Description
Whether the user should be unable to change the field value.
- Type
- Default
false
requiredbooleanfalse
- Name
- Description
Whether the user must enter a value before submitting a form.
- Type
- Default
false
inputRefReact.Ref<HTMLInputElement>—
- Name
- Description
A ref to access the hidden input element.
- Type
idstring—
- Name
- Description
The id of the input element.
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the number field is disabled.
data-readonly
Present when the number field is readonly.
data-required
Present when the number field is required.
data-valid
Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty
Present when the number field’s value has changed (when wrapped in Field.Root).
data-touched
Present when the number field has been touched (when wrapped in Field.Root).
data-filled
Present when the number field is filled (when wrapped in Field.Root).
data-focused
Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing
Present while scrubbing.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the number field is disabled. | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the number field’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). | |
data-filled | Present when the number field is filled (when wrapped in Field.Root). | |
data-focused | Present when the number field is focused (when wrapped in Field.Root). | |
data-scrubbing | Present while scrubbing. | |
NumberField.Root.StateHide
NumberField.Root.ChangeEventReasonHide
NumberField.Root.ChangeEventDetailsHide
NumberField.Root.CommitEventReasonHide
NumberField.Root.CommitEventDetailsHide
ScrubArea
An interactive area where the user can click and drag to change the field value.
Renders a <span> element.
direction'horizontal' | 'vertical''horizontal'
- Name
- Description
Cursor movement direction in the scrub area.
- Type
- Default
'horizontal'
pixelSensitivitynumber2
- Name
- Description
Determines how many pixels the cursor must move before the value changes. A higher value will make scrubbing less sensitive.
- Type
- Default
2
teleportDistancenumber—
- Name
- Description
If specified, determines the distance that the cursor may move from the center of the scrub area before it will loop back around.
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the number field is disabled.
data-readonly
Present when the number field is readonly.
data-required
Present when the number field is required.
data-valid
Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty
Present when the number field’s value has changed (when wrapped in Field.Root).
data-touched
Present when the number field has been touched (when wrapped in Field.Root).
data-filled
Present when the number field is filled (when wrapped in Field.Root).
data-focused
Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing
Present while scrubbing.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the number field is disabled. | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the number field’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). | |
data-filled | Present when the number field is filled (when wrapped in Field.Root). | |
data-focused | Present when the number field is focused (when wrapped in Field.Root). | |
data-scrubbing | Present while scrubbing. | |
NumberField.ScrubArea.StateHide
ScrubAreaCursor
A custom element to display instead of the native cursor while using the scrub area.
Renders a <span> element.
This component uses the Pointer Lock API, which may prompt the browser to display a related notification. It is disabled in Safari to avoid a layout shift that this notification causes there.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the number field is disabled.
data-readonly
Present when the number field is readonly.
data-required
Present when the number field is required.
data-valid
Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty
Present when the number field’s value has changed (when wrapped in Field.Root).
data-touched
Present when the number field has been touched (when wrapped in Field.Root).
data-filled
Present when the number field is filled (when wrapped in Field.Root).
data-focused
Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing
Present while scrubbing.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the number field is disabled. | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the number field’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). | |
data-filled | Present when the number field is filled (when wrapped in Field.Root). | |
data-focused | Present when the number field is focused (when wrapped in Field.Root). | |
data-scrubbing | Present while scrubbing. | |
NumberField.ScrubAreaCursor.PropsHide
Re-Export of ScrubAreaCursor props as NumberFieldScrubAreaCursorProps
NumberField.ScrubAreaCursor.StateHide
Group
Groups the input with the increment and decrement buttons.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the number field is disabled.
data-readonly
Present when the number field is readonly.
data-required
Present when the number field is required.
data-valid
Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty
Present when the number field’s value has changed (when wrapped in Field.Root).
data-touched
Present when the number field has been touched (when wrapped in Field.Root).
data-filled
Present when the number field is filled (when wrapped in Field.Root).
data-focused
Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing
Present while scrubbing.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the number field is disabled. | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the number field’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). | |
data-filled | Present when the number field is filled (when wrapped in Field.Root). | |
data-focused | Present when the number field is focused (when wrapped in Field.Root). | |
data-scrubbing | Present while scrubbing. | |
NumberField.Group.StateHide
Decrement
A stepper button that decreases the field value when clicked.
Renders a <button> element.
nativeButtonbooleantrue
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (for example,<div>).- Type
- Default
true
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the number field is disabled.
data-readonly
Present when the number field is readonly.
data-required
Present when the number field is required.
data-valid
Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty
Present when the number field’s value has changed (when wrapped in Field.Root).
data-touched
Present when the number field has been touched (when wrapped in Field.Root).
data-filled
Present when the number field is filled (when wrapped in Field.Root).
data-focused
Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing
Present while scrubbing.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the number field is disabled. | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the number field’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). | |
data-filled | Present when the number field is filled (when wrapped in Field.Root). | |
data-focused | Present when the number field is focused (when wrapped in Field.Root). | |
data-scrubbing | Present while scrubbing. | |
NumberField.Decrement.StateHide
Input
The native input control in the number field.
Renders an <input> element.
aria-roledescriptionstring'Number field'
- Description
A user-friendly description of the input’s role for assistive tech. This is a role description, not an accessible name — use
Field.Labeloraria-labelto name the control.- Type
- Default
'Number field'
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the number field is disabled.
data-readonly
Present when the number field is readonly.
data-required
Present when the number field is required.
data-valid
Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty
Present when the number field’s value has changed (when wrapped in Field.Root).
data-touched
Present when the number field has been touched (when wrapped in Field.Root).
data-filled
Present when the number field is filled (when wrapped in Field.Root).
data-focused
Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing
Present while scrubbing.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the number field is disabled. | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the number field’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). | |
data-filled | Present when the number field is filled (when wrapped in Field.Root). | |
data-focused | Present when the number field is focused (when wrapped in Field.Root). | |
data-scrubbing | Present while scrubbing. | |
NumberField.Input.StateHide
Increment
A stepper button that increases the field value when clicked.
Renders a <button> element.
nativeButtonbooleantrue
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (for example,<div>).- Type
- Default
true
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the number field is disabled.
data-readonly
Present when the number field is readonly.
data-required
Present when the number field is required.
data-valid
Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty
Present when the number field’s value has changed (when wrapped in Field.Root).
data-touched
Present when the number field has been touched (when wrapped in Field.Root).
data-filled
Present when the number field is filled (when wrapped in Field.Root).
data-focused
Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing
Present while scrubbing.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the number field is disabled. | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-valid | Present when the number field is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the number field is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the number field’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the number field has been touched (when wrapped in Field.Root). | |
data-filled | Present when the number field is filled (when wrapped in Field.Root). | |
data-focused | Present when the number field is focused (when wrapped in Field.Root). | |
data-scrubbing | Present while scrubbing. | |