NumberInput
NumberInput
component allows users to input numbers.Basic usage
defaultValue
prop to set the initial value, and access this from value
on the
component state.tsxCopied1<NumberInput id="numberInput" label="Input your age" />2<Text>Your age is {numberInputState.value}</Text>
Ranges and step size
min
, max
, and step
of the number input. Note that precision
also needs to be
set for fractional steps.tsxCopied1<NumberInput2label="Pizzas"3description="Each increment adds one slice (1/8)"4min={0}5max={2}6step={0.125}7precision={3}8/>
Formats
format
prop can be set to "currency" or "percent".tsxCopied1<NumberInput label="Price" id="euros" format="currency" precision={2} currency="EUR" />2<NumberInput3label="Discount"4id="percent"5format="percent"6precision={4}7step={0.005}8min={0}9max={1}10/>11<Text>Final price: € {(euros.value * (1 - percent.value)).toFixed(2)}</Text>
Component API
A three letter currency code to use, such as GBP, if format
is set to
currency
.
The input's disabled state on initial render.
The input value on initial render.
Description displayed below the input.
Disables the input. Prefer to use defaultDisabled and component state.
Error text displayed below the input.
The formatting style to use.
If true, the element will grow to fill available space.
This prop works only if the element is a direct child of a Stack.
Removes increment/decrement controls.
Adds an icon to the left of the input.
The ID referenced by the global component state.
Label displayed above the input.
Maximum possible value. Inputs are clamped to this maximum.
Minimum possible value. Inputs are clamped to this minimum.
Callback when input changes when using as a controlled component. Prefer using the global component state.
Number of digits after the decimal point.
The input's border radius.
If precision
is set, removes the trailing zeros.
Adds red asterisk on the right side of label and sets required on input element
Input size.
Number by which value will be incremented/decremented with controls and
up/down arrows. Specify precision
if using a non-integer step.
A single function or an array of functions that validate the input value.
The value of the input when using as a controlled component. Prefer using defaultValue and the global component state.
Input appearance.
State API
Whether the number input is disabled
Sets the disabled value of the number input. If the disabled
value is not provided, the number input will be disabled
Sets the value of the number input
The number currently in the number input