React
Usage
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.
React
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.
React
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.
React
Step
Pass the step prop to change the increment or decrement interval of the number input.
React
Controlled
Pass the value and onValueChange props to control the value of the number input.
React
Mouse Wheel
Pass the allowMouseWheel prop to enable or disable the mouse wheel to change the value of the number input.
React
Disabled
Pass the disabled prop to disable the number input.
React
Invalid
Use the Field component and the invalid prop to indicate that the number input is invalid.
React
Helper Text
Compose the Field and Field.HelperText components to add helper text to the number input.
React
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.
React
Scrubber
Use the NumberInput.Scrubber component to make the number input supports scrubber interactions.
React
Closed Component
Here is an example of how to use the NumberInput component in a closed manner.
and use it like this: