Skip to content

NumberInput

Input component for numeric values (integers, floats) rendering an <input type="number"> with parsing & formatting support.

import { NumberInput } from '@/components/admin';
<NumberInput source="price" />
<NumberInput source="price" step={0.1} min={0} max={100} placeholder="Enter a price" />

Internally manages a local string state so users can type incomplete numbers (e.g. ’-’) before parsing.

PropRequiredTypeDefaultDescription
sourceRequiredstring-Field name
classNameOptionalstring-CSS classes
defaultValueOptionalboolean-Default value
disabledOptionalboolean-Disable input
formatOptionalfunction-Callback taking the value from the form state, and returning the input value.
helperTextOptionalReactNode-Help text
labelOptionalstring | falseInferredCustom / hide label
minOptionalnumber-The minimum value allowed for the input
maxOptionalnumber-The maximum value allowed for the
parseOptional(value:string)=>number-Callback taking the value from the input, and returning the value to be stored in the form state.
 placeholderOptionalstring-Placeholder text
stepOptionalnumber | 'any'-The step attribute to use. Use ‘any’ to allow any float value.
validateOptionalValidator | Validator[]-Validation

Additional props are passed to the underlying <input type="number"> element, e.g. min, max, etc.

It’s common to need to transform the value from the form state before passing it to the input, and vice-versa. You can achieve this by using the format and parse props.

form state value --> format --> html input value
(typed) <-- parse <-- (string)

For example, you may want to store an amount in cents in the form state, but display it in dollars in the input:

{/* Unit Price is stored in cents, i.e. 123 means 1.23 */}
<NumberInput
source="unit_price"
format={v => String(v * 100)}
parse={v => parseFloat(v) / 100}
/>