NumberInput
Capture number from user
Source
LLM docs
Docs
PackageIcon
Usage
NumberInput is based on react-number-format.
It supports most of the props from the NumericFormat component in the original package.
NumberInput component supports Input and Input.Wrapper component features and all input element props. The NumberInput documentation does not include all features supported by the component – see the Input documentation to learn about all available features.
Input description
Loading state
Set loading prop to display a loading indicator. By default, the loader is displayed on the right side of the input.
You can change the position with the loadingPosition prop to 'left' or 'right'. This is useful for async operations like API calls, searches, or validations:
Controlled
Uncontrolled
NumberInput can be used with uncontrolled forms the same way as a native input[type="number"].
Set the name attribute to include number input value in FormData object on form submission.
To control the initial value in uncontrolled forms, use the defaultValue prop.
Example usage of uncontrolled NumberInput with FormData:
Value type
The value, defaultValue, and onChange props can be either string or number. In all cases
when the NumberInput value can be represented as a number, the onChange function is called
with a number (for example 55, 1.28, -100, etc.). But there are several cases when
it is not possible to represent the value as a number:
- Empty state is represented as an empty string –
'' - Numbers that are larger than
Number.MAX_SAFE_INTEGER - 1or smaller thanNumber.MIN_SAFE_INTEGER + 1are represented as strings –'90071992547409910' - Numbers with trailing decimal separators or trailing decimal zeros are represented as strings –
0.,0.0,-0.00, etc.
onChange vs onValueChange
NumberInput provides two callback props for handling value changes:
-
onChange: Receives a simplified value asnumber | string. This is the recommended callback for most use cases. The value is a number when possible, and a string in edge cases (empty input, very large numbers, trailing decimals). -
onValueChange: Receives the full payload fromreact-number-format, which includes:floatValue: The numeric value (orundefined)formattedValue: The formatted string value (with prefix/suffix/separators)value: The raw unformatted string value- Additional metadata about the change source
Use onValueChange when you need access to the formatted value or metadata about the change (e.g., whether it came from user typing, increment/decrement buttons, or programmatic changes). For simple form handling, onChange is sufficient.
min and max
Set the min and max props to limit the input value:
Clamp behavior
By default, the value is clamped when the input is blurred. If you set clampBehavior="strict",
it will not be possible to enter a value outside of the min/max range. Note that this option
may cause issues if you have tight min and max, for example min={10} and max={20}.
If you need to disable value clamping entirely, set clampBehavior="none".
Prefix and suffix
Set the prefix and suffix props to add a given string to the start or end of the input value:
Negative numbers
By default, negative numbers are allowed. Set allowNegative={false} to allow only positive numbers.
Decimal numbers
By default, decimal numbers are allowed. Set allowDecimal={false} to allow only integers.
Decimal scale
The decimalScale controls how many decimal places are allowed:
Fixed decimal scale
Set fixedDecimalScale to always display a fixed number of decimal places:
Decimal separator
Set decimalSeparator to change the decimal separator character:
Thousand separator
Set the thousandSeparator prop to separate thousands with a character. You can control
the grouping logic with thousandsGroupStyle, which accepts: thousand, lakh, wan, none values.
Trim leading zeros on blur
By default, leading zeros are removed when the input loses focus (e.g., 00100 becomes 100).
You can disable this behavior by setting trimLeadingZeroesOnBlur={false}:
Left and right sections
NumberInput supports leftSection and rightSection props. These sections are rendered with absolute positioning inside the input wrapper. You can use them to display icons, input controls, or any other elements.
You can use the following props to control sections styles and content:
rightSection/leftSection– React node to render on the corresponding side of inputrightSectionWidth/leftSectionWidth– controls the width of the right section and padding on the corresponding side of the input. By default, it is controlled by the componentsizeprop.rightSectionPointerEvents/leftSectionPointerEvents– controls thepointer-eventsproperty of the section. If you want to render a non-interactive element, set it tononeto pass clicks through to the input.
Increment/decrement controls
By default, the right section is occupied by increment and decrement buttons.
To hide them, set the hideControls prop. You can also use the rightSection prop to render anything
in the right section to replace the default controls.
Increment/decrement on hold
Set the stepHoldDelay and stepHoldInterval props to define behavior when increment/decrement controls are clicked and held:
Step value when clicking and holding increment/decrement buttons
Steps get faster over time when holding the control button
Custom increment and decrement controls
You can get a ref with increment and decrement functions to create custom controls:
Error state
Invalid name
Disabled state
Styles API
NumberInput supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.
Description
Error
Component Styles API
Hover over selectors to highlight corresponding elements
Get element ref
Accessibility
If NumberInput is used without the label prop, it will not be announced properly by screen readers:
Set aria-label to make the input accessible. In this case the label will not be visible, but screen readers will announce it:
If the label prop is set, the input will be accessible and it is not required to set aria-label: