NumberInput
Capture number from user
Import
Source
Docs
Package
Usage
NumberInput
component supports Input and Input.Wrapper components features and all input
element props. NumberInput
documentation does not include all features supported by the component – see Input documentation to learn about all available features.
Input description
Controlled
min and max
Set 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 value outside of 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 prefix
and suffix
props to add 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
decimalScale
controls how many decimal places are allowed:
Fixed decimal scale
Set fixedDecimalScale
to always display fixed number of decimal places:
Decimal separator
Set decimalSeparator
to change decimal separator character:
Thousand separator
Set thousandSeparator
prop to separate thousands with a character. You can control
grouping logic with thousandsGroupStyle
, it accepts: thousand
, lakh
, wan
, none
values.
Right section
By default, the right section is occupied by increment and decrement buttons.
To hide them, set hideControls
prop. You can also use rightSection
prop to render anything
in the right section to replace the default controls.
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 Styles API, you can add styles to any inner element of the component withclassNames
prop. Follow 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 label
prop, it will not be announced properly by screen reader:
Set aria-label
to make the input accessible. In this case label will not be visible, but screen reader will announce it:
If label
prop is set, input will be accessible it is not required to set aria-label
: