Number Field
A numeric input element with increment and decrement buttons, and a scrub area.
API reference
Import the component and place its parts the following way:
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>
Root
Groups all parts of the number field and manages its state.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
allowWheelScrub | boolean | false | |
autoFocus | boolean | false | |
className | string | (state) => string | undefined | |
defaultValue | number | undefined | |
disabled | boolean | false | |
format | Intl.NumberFormatOptions | undefined | |
id | string | undefined | |
invalid | boolean | false | |
largeStep | number | 10 | |
max | number | undefined | |
min | number | undefined | |
name | string | undefined | |
onValueChange | (value, event) => void | undefined | |
readOnly | boolean | false | |
render | | React.ReactElement | undefined | |
required | boolean | false | |
smallStep | number | 0.1 | |
step | number | undefined | |
value | number | undefined |
Attribute | Description | |
---|---|---|
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). | |
data-disabled | Present when the number field is disabled. | |
data-invalid | Present when the number field is in invalid state (when wrapped in Field.Root). | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-scrubbing | Present while scrubbing. | |
data-touched | Present when the number field has been thouched (when wrapped in Field.Root). | |
data-valid | Present when the number field is in valid state (when wrapped in Field.Root).. |
ScrubArea
An interactive area where the user can click and drag to change the field value.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
direction | 'horizontal' | 'vertical' | 'horizontal' | |
pixelSensitivity | number | 2 | |
render | | React.ReactElement | undefined | |
teleportDistance | number | undefined |
Attribute | Description | |
---|---|---|
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). | |
data-disabled | Present when the number field is disabled. | |
data-invalid | Present when the number field is in invalid state (when wrapped in Field.Root). | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-scrubbing | Present while scrubbing. | |
data-touched | Present when the number field has been thouched (when wrapped in Field.Root). | |
data-valid | Present when the number field is in valid state (when wrapped in Field.Root).. |
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.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). | |
data-disabled | Present when the number field is disabled. | |
data-invalid | Present when the number field is in invalid state (when wrapped in Field.Root). | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-scrubbing | Present while scrubbing. | |
data-touched | Present when the number field has been thouched (when wrapped in Field.Root). | |
data-valid | Present when the number field is in valid state (when wrapped in Field.Root).. |
Group
Groups the input with the increment and decrement buttons.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). | |
data-disabled | Present when the number field is disabled. | |
data-invalid | Present when the number field is in invalid state (when wrapped in Field.Root). | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-scrubbing | Present while scrubbing. | |
data-touched | Present when the number field has been thouched (when wrapped in Field.Root). | |
data-valid | Present when the number field is in valid state (when wrapped in Field.Root).. |
Decrement
A stepper button that decreases the field value when clicked.
Renders an <button>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). | |
data-disabled | Present when the number field is disabled. | |
data-invalid | Present when the number field is in invalid state (when wrapped in Field.Root). | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-scrubbing | Present while scrubbing. | |
data-touched | Present when the number field has been thouched (when wrapped in Field.Root). | |
data-valid | Present when the number field is in valid state (when wrapped in Field.Root).. |
Input
The native input control in the number field.
Renders an <input>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). | |
data-disabled | Present when the number field is disabled. | |
data-invalid | Present when the number field is in invalid state (when wrapped in Field.Root). | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-scrubbing | Present while scrubbing. | |
data-touched | Present when the number field has been thouched (when wrapped in Field.Root). | |
data-valid | Present when the number field is in valid state (when wrapped in Field.Root).. |
Increment
A stepper button that increases the field value when clicked.
Renders an <button>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-dirty | Present when the number field's value has changed (when wrapped in Field.Root). | |
data-disabled | Present when the number field is disabled. | |
data-invalid | Present when the number field is in invalid state (when wrapped in Field.Root). | |
data-readonly | Present when the number field is readonly. | |
data-required | Present when the number field is required. | |
data-scrubbing | Present while scrubbing. | |
data-touched | Present when the number field has been thouched (when wrapped in Field.Root). | |
data-valid | Present when the number field is in valid state (when wrapped in Field.Root).. |