Number Field

A numeric input element with increment and decrement buttons, and a scrub area.

View as Markdown

Anatomy

Import the component and assemble its parts:

Anatomy

API reference

Root

Groups all parts of the number field and manages its state. Renders a <div> element.

PropTypeDefault
name

string

undefined

defaultValue

number

undefined

value

number | null

undefined

onValueChange

((value: number | null, event: Event | undefined) => void)

undefined

locale

Intl.LocalesArgument

undefined

snapOnStep

boolean

false

step

number

1

smallStep

number

0.1

largeStep

number

10

min

number

undefined

max

number

undefined

allowWheelScrub

boolean

false

format

Intl.NumberFormatOptions

undefined

disabled

boolean

false

readOnly

boolean

false

required

boolean

false

inputRef

Ref<HTMLInputElement>

undefined

id

string

undefined

className

| string
| ((state: NumberField.Root.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NumberField.Root.State) => ReactElement)

undefined

Attribute
Description
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
data-scrubbing

ScrubArea

An interactive area where the user can click and drag to change the field value. Renders a <span> element.

PropTypeDefault
direction

'horizontal' | 'vertical'

'horizontal'

pixelSensitivity

number

2

teleportDistance

number

undefined

className

| string
| ((state: NumberField.ScrubArea.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NumberField.ScrubArea.State) => ReactElement)

undefined

Attribute
Description
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
data-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.

PropTypeDefault
className

| string
| ((state: NumberField.ScrubAreaCursor.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NumberField.ScrubAreaCursor.State) => ReactElement)

undefined

Attribute
Description
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
data-scrubbing

Group

Groups the input with the increment and decrement buttons. Renders a <div> element.

PropTypeDefault
className

| string
| ((state: NumberField.Group.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NumberField.Group.State) => ReactElement)

undefined

Attribute
Description
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
data-scrubbing

Decrement

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

PropTypeDefault
className

| string
| ((state: NumberField.Decrement.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NumberField.Decrement.State) => ReactElement)

undefined

Attribute
Description
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
data-scrubbing

Input

The native input control in the number field. Renders an <input> element.

PropTypeDefault
aria-roledescription

string

'Number field'

className

| string
| ((state: NumberField.Input.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NumberField.Input.State) => ReactElement)

undefined

Attribute
Description
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
data-scrubbing

Increment

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

PropTypeDefault
className

| string
| ((state: NumberField.Increment.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NumberField.Increment.State) => ReactElement)

undefined

Attribute
Description
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused
data-scrubbing