NumberInput component is similar to the Input
component, but it has controls for incrementing or decrementing numeric values.
It follows the WAI-ARIA authoring practices for the Spinbutton widget.
Chakra UI exports 5 components for the NumberInput.
NumberInput: The wrapper that provides context and logic to the components.
NumberInputStepper: The wrapper for the input's stepper buttons.
NumberIncrementStepper: The button to increment the value of the input.
NumberDecrementStepper: The button to decrement the value of the input.
NumberInput is composed of smaller components to give you control of the
styling of each part.
min prop or
max prop to set an upper and lower limit for the input.
By default, the input will restrict the value to stay within the specified
step prop to change the step size when you increment or decrement the
value. By default, the value is rounded to match the number of decimals in the
In some cases, you might need the value to be rounded to specific decimal
points. Simply pass the
precision prop and set it to the number of decimal
In most cases, users can type custom values in the input field. If the typed
value is greater than the
max, the value is reset to
max when the user blur
out of the input.
To disable this behavior, pass
clampValueOnBlur and set to
In this example, try to type a value greater than the max. It won't reset the value on blur.
In some scenarios, you might not want to block out of range values. Pass the
clampValueOnBlur props and set them to
support this use case.
The NumberInput will be set
trueinternally when the value is out of range. Out of range means that the
valueis great than
maxor less than
Input component, you can pass the
size prop to change the size of
You can change the style of any part of the components using style props. You can also change the icons used in the steppers.
A common use case is to combine the
NumberInput with a
Slider. Here's an
example of how to do that:
Sometimes, you might need to create a mobile version of the number input. Here's
how you can leverage the
useNumberInput hook to build one.
NumberInput component supports the ability to increment or decrement
values using the mouse wheel events. To activate this, pass the
spinbuttonto denote that users are to select from a range of discrete values using an up and down arrows on the keyboard.
aria-valueminset to the minimum value allowed for the spinbutton.
aria-valuemaxset to the maximum value allowed for the spinbutton. attribute should be applied to the spinbutton.
aria-valuenowset to the current value of the
trueto make them invisible to screen readers.
10 * step.
Flex with some additional props listed below.
|allowMouseWheel||If `true`, the input's value will change based on mouse wheel||-|
|clampValueOnBlur||This controls the value update when you blur out of the input. - If `true` and the value is greater than `max`, the value will be reset to `max` - Else, the value remains the same.|
|css||The emotion's css style object||-|
|defaultValue||The initial value of the counter. Should be less than `max` and greater than `min`||-|
|errorBorderColor||The border color when the input is invalid. Use color keys in `theme.colors` @example errorBorderColor = "red.500"||-|
|focusBorderColor||The border color when the input is focused. Use color keys in `theme.colors` @example focusBorderColor = "blue.500"||-|
|focusInputOnChange||If `true`, the input will be focused as you increment or decrement the value with the stepper|
|getAriaValueText||This is used to format the value so that screen readers can speak out a more human-friendly value. It is used to set the `aria-valuetext` property of the input||-|
|id||The `id` to use for the number input field.||-|
|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|
|isDisabled||If `true`, the input will be disabled||-|
|isFullWidth||If `true`, the input element will span the full width of its parent||-|
|isInvalid||If `true`, the input will have `aria-invalid` set to `true`||-|
|isReadOnly||If `true`, the input will be in readonly mode||-|
|keepWithinRange||This controls the value update behavior in general. - If `true` and you use the stepper or up/down arrow keys, the value will not exceed the `max` or go lower than `min` - If `false`, the value will be allowed to go out of range.|
|max||The maximum value of the counter|
|min||The minimum value of the counter|
|onChange||The callback fired when the value changes||-|
|pattern||The pattern used to check the <input> element's value against on form submission.|
|precision||The number of decimal points used to round the value||-|
|step||The step used to increment or decrement the value|
|value||The value of the counter. Should be less than `max` and greater than `min`||-|
Input so you can pass all
Flex so you can pass all
NumberIncrementStepper composes the
so you can pass all