Number Field
A numeric input element with increment and decrement buttons, and a scrub area.
View as MarkdownAnatomy
Import the component and assemble its parts:
import { NumberField } from '@base-ui-components/react/number-field';
<NumberField.Root>
<NumberField.ScrubArea>
<NumberField.ScrubAreaCursor />
</NumberField.ScrubArea>
<NumberField.Group>
<NumberField.Decrement />
<NumberField.Input />
<NumberField.Increment />
</NumberField.Group>
</NumberField.Root>
API reference
Root
Groups all parts of the number field and manages its state.
Renders a <div>
element.
name
string
string
- Name
- Description
Identifies the field when a form is submitted.
- Type
string
defaultValue
number
number
- Name
- Description
The uncontrolled value of the field when it’s initially rendered.
To render a controlled number field, use the
value
prop instead.- Type
number
value
number | null
number | null
- Name
- Description
The raw numeric value of the field.
- Type
number | null
onValueChange
function
function
- Name
- Description
Callback fired when the number value changes.
- Type
((value: number | null, event: Event | undefined) => void)
locale
Intl.LocalesArgument
Intl.LocalesArgument
- Name
- Description
The locale of the input element. Defaults to the user's runtime locale.
- Type
Intl.LocalesArgument
snapOnStep
boolean
(default: false
)
boolean
false
- Name
- Description
Whether the value should snap to the nearest step when incrementing or decrementing.
- Type
boolean
- Default
false
step
number
(default: 1
)
number
1
- Name
- Description
Amount to increment and decrement with the buttons and arrow keys, or to scrub with pointer movement in the scrub area.
- Type
number
- Default
1
smallStep
number
(default: 0.1
)
number
0.1
- Name
- Description
The small step value of the input element when incrementing while the meta key is held. Snaps to multiples of this value.
- Type
number
- Default
0.1
largeStep
number
(default: 10
)
number
10
- Name
- Description
The large step value of the input element when incrementing while the shift key is held. Snaps to multiples of this value.
- Type
number
- Default
10
min
number
number
- Name
- Description
The minimum value of the input element.
- Type
number
max
number
number
- Name
- Description
The maximum value of the input element.
- Type
number
allowWheelScrub
boolean
(default: false
)
boolean
false
- Name
- Description
Whether to allow the user to scrub the input value with the mouse wheel while focused and hovering over the input.
- Type
boolean
- Default
false
format
Intl.NumberFormatOptions
Intl.NumberFormatOptions
- Name
- Description
Options to format the input value.
- Type
Intl.NumberFormatOptions
disabled
boolean
(default: false
)
boolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean
- Default
false
readOnly
boolean
(default: false
)
boolean
false
- Name
- Description
Whether the user should be unable to change the field value.
- Type
boolean
- Default
false
required
boolean
(default: false
)
boolean
false
- Name
- Description
Whether the user must enter a value before submitting a form.
- Type
boolean
- Default
false
inputRef
Ref<HTMLInputElement>
Ref<HTMLInputElement>
- Name
- Description
A ref to access the hidden input element.
- Type
Ref<HTMLInputElement>
id
string
string
- Name
- Description
The id of the input element.
- Type
string
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: NumberField.Root.State) => string)
render
ReactElement | function
ReactElement | 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
| ReactElement
| ((props: HTMLProps, state: NumberField.Root.State) => ReactElement)
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 valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in 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.
ScrubArea
An interactive area where the user can click and drag to change the field value.
Renders a <span>
element.
direction
'horizontal' | 'vertical'
(default: 'horizontal'
)
'horizontal' | 'vertical'
'horizontal'
- Name
- Description
Cursor movement direction in the scrub area.
- Type
'horizontal' | 'vertical'
- Default
'horizontal'
pixelSensitivity
number
(default: 2
)
number
2
- Name
- Description
Determines how many pixels the cursor must move before the value changes. A higher value will make scrubbing less sensitive.
- Type
number
- Default
2
teleportDistance
number
number
- 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
number
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: NumberField.ScrubArea.State) => string)
render
ReactElement | function
ReactElement | 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
| ReactElement
| ((props: HTMLProps, state: NumberField.ScrubArea.State) => ReactElement)
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 valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in 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.
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.
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: NumberField.ScrubAreaCursor.State) => string)
render
ReactElement | function
ReactElement | 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
| ReactElement
| ((props: HTMLProps, state: NumberField.ScrubAreaCursor.State) => ReactElement)
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 valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in 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.
Group
Groups the input with the increment and decrement buttons.
Renders a <div>
element.
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: NumberField.Group.State) => string)
render
ReactElement | function
ReactElement | 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
| ReactElement
| ((props: HTMLProps, state: NumberField.Group.State) => ReactElement)
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 valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in 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.
Decrement
A stepper button that decreases the field value when clicked.
Renders an <button>
element.
nativeButton
boolean
(default: true
)
boolean
true
- Name
- Description
Whether the component renders a native
<button>
element when replacing it via therender
prop. Set tofalse
if the rendered element is not a button (e.g.<div>
).- Type
boolean
- Default
true
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: NumberField.Decrement.State) => string)
render
ReactElement | function
ReactElement | 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
| ReactElement
| ((props: HTMLProps, state: NumberField.Decrement.State) => ReactElement)
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 valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in 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.
Input
The native input control in the number field.
Renders an <input>
element.
aria-roledescription
string
(default: 'Number field'
)
string
'Number field'
- Description
A string value that provides a user-friendly name for the role of the input.
- Type
string
- Default
'Number field'
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: NumberField.Input.State) => string)
render
ReactElement | function
ReactElement | 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
| ReactElement
| ((props: HTMLProps, state: NumberField.Input.State) => ReactElement)
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 valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in 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.
Increment
A stepper button that increases the field value when clicked.
Renders an <button>
element.
nativeButton
boolean
(default: true
)
boolean
true
- Name
- Description
Whether the component renders a native
<button>
element when replacing it via therender
prop. Set tofalse
if the rendered element is not a button (e.g.<div>
).- Type
boolean
- Default
true
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: NumberField.Increment.State) => string)
render
ReactElement | function
ReactElement | 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
| ReactElement
| ((props: HTMLProps, state: NumberField.Increment.State) => ReactElement)
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 valid state (when wrapped in Field.Root).
data-invalid
Present when the number field is in 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.