NumberInput
Usage
Controlled
Clamp on blur
Component has internal state to manage user input, when blur event is triggered
internal value is clamped with given min and max values and onChange handler is called with result.
For example, if you put 123 or -20 in age input in next example, values will be clamped on blur: 123 -> 120, -20 -> 0.
If you want to disable this behavior set noClampOnBlur prop:
Parser and formatter
With parser and formatter props you can customize how value is displayed in the input:
Min, max and step
Min and max values define upper and lower value which may be entered. When user clicks controls or presses up/down arrows, value is incremented/decremented by step:
Increment/decrement on hold
Set stepHoldDelay and stepHoldInterval props to define behavior when increment/decrement controls are clicked and hold,
this will also overwrite default up and down arrows behavior:
Decimal steps
To use decimal steps set following props:
step– decimal number, e.g.0.05precision– amount of significant digits
Decimal separator
To change decimal separator set decimalSeparator prop:
Remove controls
Controls are not rendered in these cases:
hideControlsprop is set to true- Input is disabled
variantprop is set to unstyled
Custom increment/decrement controls
NumberInput exposes increment/decrement functions with handlersRef prop.
You can use it to create custom controls:
Invalid state and error
Disabled state
Controls to increment/decrement value are not displayed when input is disabled:
With icon
Get input ref
Accessibility
NumberInput renders regular input with type="text".
Increment/decrement controls have aria-hidden attribute and cannot be focused
– users with keyboard can increment/decrement value by step with up/down arrows.
Provide aria-label in case you use component without label for screen reader support: