Skip to contents

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 the Field component. See the forms guide.

Anatomy

Import the component and assemble its parts:

Anatomy

Examples

Setting the input text imperatively

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 states, reach for actionsRef:

Setting the input text imperatively

The action can only reach states typing can reach. The string runs through the same character validation as a typed one, so anything the input would reject — stray letters, symbols the current locale and format don’t use — is ignored and the field is left unchanged. Partial entries are allowed, which is the point: '-' and '1.' pass validation even though neither parses.

The text itself is displayed as given, never formatted, and never clamped. value follows the text when it parses and is left alone when it doesn’t, which is what lets '-' sit over an existing number without clearing it. An empty string clears value.

Unlike the text, value is still validated: it is clamped to min and max unless allowOutOfRange is set. Setting '999' on a field with max={10} therefore shows 999 while value becomes 10.

Two things do set the action apart from typing, because the caller is the component’s owner rather than a user:

  • It works while the field is disabled or readOnly, which gate user interaction.
  • Its changes are final rather than pending: onValueChange and onValueCommitted both run right away, with reason: 'imperative-action'. Waiting for blur would drop the change entirely when the input is never focused.

The text still behaves as an unsaved edit, exactly as if it had been typed: it survives re-renders and external value changes. Blurring the input ends the edit and re-arms formatting, so the display returns to the formatted value on the next render — whether or not that blur changed anything.

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
Description

The uncontrolled value of the field when it’s initially rendered.

To render a controlled number field, use the value prop instead.

Type
valuenumber | null
Name
Description

The raw numeric value of the field.

Type
onValueChangefunction
Description

Callback fired when the number value changes.

The eventDetails.reason indicates 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
  • 'imperative-action' for text set through actionsRef
Type
onValueCommittedfunction
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 onValueChange when interacting with the keyboard or the mouse wheel, and when actionsRef’s setInputValue changes the value.

Warning: This is a generic event not a change event.

Type
actionsRefReact.RefObject<NumberField.Root.Actions | null>
Description

A ref to imperative actions.

  • setInputValue: Sets the raw text shown in the input element. The text goes through the same character validation as typing, so text the input would reject is ignored, but strings that aren’t parseable as a number yet, such as '-' or '.', are allowed. When the text parses, value follows it (clamped to min/max unless allowOutOfRange is set) and the change is committed right away; when it doesn’t, value is left alone. An empty string clears value. Unlike typing, this works while the field is disabled or readOnly, which gate user interaction rather than the component’s own owner.
Type
allowOutOfRangebooleanfalse
Description

When true, direct text entry may be outside the min/max range 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
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 min prop explicitly in conjunction with this prop. Specify step="any" to always disable step validation; interactive stepping then uses a base amount of 1, while the alt and shift keys still step by smallStep and largeStep.

Type
Default
1
smallStepnumber0.1
Description

The small step value of the input element when incrementing while the alt key is held. Snaps to multiples of this value when snapOnStep is enabled.

Type
Default
0.1
largeStepnumber10
Description

The large step value of the input element when incrementing while the shift key is held. Snaps to multiples of this value when snapOnStep is 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
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
Description

Whether the component should ignore user interaction.

Type
Default
false
readOnlybooleanfalse
Description

Whether the user should be unable to change the field value.

Type
Default
false
requiredbooleanfalse
Description

Whether the user must enter a value before submitting a form.

Type
Default
false
inputRefReact.Ref<HTMLInputElement>
Description

A ref to access the hidden input element.

Type
idstring
Name
Description

The id of the input element.

Type
classNamestring | function
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 ReactElement or 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.PropsHide

Re-Export of Root props as NumberFieldRootProps

NumberField.Root.StateHide

NumberField.Root.ActionsHide

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'
Description

Cursor movement direction in the scrub area.

Type
Default
'horizontal'
pixelSensitivitynumber2
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
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
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 ReactElement or 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.PropsHide

Re-Export of ScrubArea props as NumberFieldScrubAreaProps

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
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 ReactElement or 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
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 ReactElement or 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.PropsHide

Re-Export of Group props as NumberFieldGroupProps

NumberField.Group.StateHide

Decrement

A stepper button that decreases the field value when clicked. Renders a <button> element.

nativeButtonbooleantrue
Description

Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).

Type
Default
true
classNamestring | function
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 ReactElement or 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.PropsHide

Re-Export of Decrement props as NumberFieldDecrementProps

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.Label or aria-label to name the control.

Type
Default
'Number field'
classNamestring | function
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 ReactElement or 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.PropsHide

Re-Export of Input props as NumberFieldInputProps

NumberField.Input.StateHide

Increment

A stepper button that increases the field value when clicked. Renders a <button> element.

nativeButtonbooleantrue
Description

Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).

Type
Default
true
classNamestring | function
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 ReactElement or 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.Increment.PropsHide

Re-Export of Increment props as NumberFieldIncrementProps

NumberField.Increment.StateHide