Park UI

Number Input

A form control for entering numbers with increment and decrement buttons.

Installation

Usage

Info

If you prefer a closed component composition, check out the snippet below.

Shortcuts

The NumberInput component provides a set of shortcuts for common use cases

NumberInput.Control

This component renders the NumberInput.IncrementTrigger and NumberInput.DecrementTrigger within it by default.

Writing this:

is shorthand for writing this if you don't need to customize the triggers:

Examples

Sizes

Pass the size prop to change the size of the number input.

Formatting

Pass the formatOptions prop to format the number input value. The value of this maps to Intl.NumberFormatOptions and is applied based on the current locale.

Min and Max

Pass the min and max props to set the minimum and maximum values of the number input.

If value entered is less than min or greater than max, the value will be clamped to the nearest boundary on blur, or enter key press.

Step

Pass the step prop to change the increment or decrement interval of the number input.

Controlled

Pass the value and onValueChange props to control the value of the number input.

Mouse Wheel

Pass the allowMouseWheel prop to enable or disable the mouse wheel to change the value of the number input.

Disabled

Pass the disabled prop to disable the number input.

Invalid

Use the Field component and the invalid prop to indicate that the number input is invalid.

The entry is invalid

Helper Text

Compose the Field and Field.HelperText components to add helper text to the number input.

Please enter a number between 5 and 50

Element

Here's an example of how to compose the number input with the input group component to add an element on either the left or right.

Scrubber

Use the NumberInput.Scrubber component to make the number input supports scrubber interactions.

Closed Component

Here is an example of how to use the NumberInput component in a closed manner.

and use it like this:

Props

Root

PropDefaultType
size'md'
'sm' | 'md' | 'lg' | 'xl'
variant'outline'
'outline'
allowOverflowtrue
boolean

Whether to allow the value overflow the min/max range

clampValueOnBlurtrue
boolean

Whether to clamp the value when the input loses focus (blur)

focusInputOnChangetrue
boolean

Whether to focus input when the value changes

inputMode\decimal\
InputMode

Hints at the type of data that might be entered by the user. It also determines the type of keyboard shown to the user on mobile devices

locale\en-US\
string

The current locale. Based on the BCP 47 definition.

maxNumber.MAX_SAFE_INTEGER
number

The maximum value of the number input

minNumber.MIN_SAFE_INTEGER
number

The minimum value of the number input

pattern\-?[0-9]*(.[0-9]+)?\
string

The pattern used to check the <input> element's value against

spinOnPresstrue
boolean

Whether to spin the value when the increment/decrement button is pressed

step1
number

The amount to increment or decrement the value by

allowMouseWheel
boolean

Whether to allow mouse wheel to change the value

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

defaultValue
string

The initial value of the input when rendered. Use when you don't need to control the value of the input.

disabled
boolean

Whether the number input is disabled.

form
string

The associate form of the input element.

formatOptions
NumberFormatOptions

The options to pass to the `Intl.NumberFormat` constructor

id
string

The unique identifier of the machine.

ids
Partial<{ root: string label: string input: string incrementTrigger: string decrementTrigger: string scrubber: string }>

The ids of the elements in the number input. Useful for composition.

invalid
boolean

Whether the number input value is invalid.

name
string

The name attribute of the number input. Useful for form submission.

onFocusChange
(details: FocusChangeDetails) => void

Function invoked when the number input is focused

onValueChange
(details: ValueChangeDetails) => void

Function invoked when the value changes

onValueInvalid
(details: ValueInvalidDetails) => void

Function invoked when the value overflows or underflows the min/max range

readOnly
boolean

Whether the number input is readonly

required
boolean

Whether the number input is required

translations
IntlTranslations

Specifies the localized strings that identifies the accessibility elements and their states

value
string

The controlled value of the input