Skip to content

NumberField

The NumberField component provides a customizable number field that can be used to collect user information, such as age, quantity, or other types of numerical data. It is a wrapper around the native <input type="number" /> element, and includes an optional label and validation alert. The label and input are automatically associated for screen readers.

Usage Guidelines

States

Default

The default state of the number field is used to indicate that the user has not yet entered any information.

Disabled

The disabled state of the number field is used to indicate that the user cannot interact with the field.

Props

interface NumberFieldProps
decrementAriaLabel ? string

A custom aria-label for the decrement button. If not provided, the localized string "Decrement" is used.

incrementAriaLabel ? string

A custom aria-label for the increment button. If not provided, the localized string "Increment" is used.

isWheelDisabled ? boolean

Enables or disables changing the value with scroll.

formatOptions ? NumberFormatOptions

Formatting options for the value displayed in the number field. This also affects what characters are allowed to be typed by the user.

isDisabled ? boolean

Whether the input is disabled.

isReadOnly ? boolean

Whether the input can be selected but not changed by the user.

isRequired ? boolean

Whether user input is required on the input before form submission.

isInvalid ? boolean

Whether the input value is invalid.

validate ? (value: number) => true | ValidationError | null

A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if validationBehavior="native". For realtime validation, use the isInvalid prop instead.

autoFocus ? boolean

Whether the element should receive focus on render.

onFocus ? (e: FocusEvent) => void

Handler that is called when the element receives focus.

onBlur ? (e: FocusEvent) => void

Handler that is called when the element loses focus.

onFocusChange ? (isFocused: boolean) => void

Handler that is called when the element's focus status changes.

onKeyDown ? (e: KeyboardEvent) => void

Handler that is called when a key is pressed.

onKeyUp ? (e: KeyboardEvent) => void

Handler that is called when a key is released.

value ? number

The current value (controlled).

defaultValue ? number

The default value (uncontrolled).

onChange ? (value: number) => void

Handler that is called when the value changes.

minValue ? number

The smallest value allowed for the input.

maxValue ? number

The largest value allowed for the input.

step ? number

The amount that the input value changes with each increment or decrement "tick".

id ? string

The element's unique identifier. See MDN.

onCopy ? ClipboardEventHandler

Handler that is called when the user copies text. See MDN.

onCut ? ClipboardEventHandler

Handler that is called when the user cuts text. See MDN.

onPaste ? ClipboardEventHandler

Handler that is called when the user pastes text. See MDN.

onCompositionStart ? CompositionEventHandler

Handler that is called when a text composition system starts a new text composition session. See MDN.

onCompositionEnd ? CompositionEventHandler

Handler that is called when a text composition system completes or cancels the current text composition session. See MDN.

onCompositionUpdate ? CompositionEventHandler

Handler that is called when a new character is received in the current text composition session. See MDN.

onSelect ? ReactEventHandler

Handler that is called when text in the input is selected. See MDN.

onBeforeInput ? FormEventHandler

Handler that is called when the input value is about to be modified. See MDN.

onInput ? FormEventHandler

Handler that is called when the input value is modified. See MDN.

validationBehavior ? "native" | "aria"

Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.

Defaults to 'native'
name ? string

The name of the input element, used when submitting an HTML form. See MDN.

form ? string

The <form> element to associate the input with. The value of this attribute must be the id of a <form> in the same document. See MDN.

children ? ChildrenOrFunction

The children of the component. A function may be provided to alter the children based on component state.

className ? ClassNameOrFunction

The CSS className for the element. A function may be provided to compute the class based on component state.

style ? StyleOrFunction

The inline style for the element. A function may be provided to compute the style based on component state.

slot ? string | null

A slot name for the component. Slots allow the component to receive props from a parent component. An explicit null value indicates that the local props completely override all props received from a parent.