Number Input
The Number Input component provides users with a field for integer values, and buttons to increment or decrement the value.
NumberInput API
Import
import { Unstable_NumberInput as NumberInput } from '@mui/base/Unstable_NumberInput';
// or
import { Unstable_NumberInput as NumberInput } from '@mui/base';
Props
Props of the native component are also available.
If true
, the component is disabled. The prop defaults to the value (false
) inherited from the parent FormControl component.
Type:
bool
If true
, the input
will indicate an error by setting the aria-invalid
attribute on the input and the Mui-error
class on the root element.
Type:
bool
Callback fired after the value is clamped and changes - when the input
is blurred or when the stepper buttons are triggered. Called with undefined
when the value is unset.
Type:
func
Signature:
function(event: React.FocusEvent | React.PointerEvent | React.KeyboardEvent, value: number | undefined) => void
event
The event source of the callbackvalue
The new value of the component
Callback fired when the input
value changes after each keypress, before clamping is applied. Note that event.target.value
may contain values that fall outside of min
and max
or are otherwise "invalid".
Type:
func
Signature:
function(event: React.ChangeEvent) => void
event
The event source of the callback.
If true
, the input
element becomes read-only. The stepper buttons remain active, with the addition that they are now keyboard focusable.
Type:
bool
Default:
false
If true
, the input
element is required. The prop defaults to the value (false
) inherited from the parent FormControl component.
Type:
bool
Multiplier applied to step
if the shift key is held while incrementing or decrementing the value. Defaults to 10
.
Type:
number
The props used for each slot inside the NumberInput.
Type:
{ decrementButton?: func | object, incrementButton?: func | object, input?: func | object, root?: func | object }
Default:
{}
The components used for each slot inside the InputBase. Either a string to use a HTML element or a component.
See Slots API below for more details.
Type:
{ decrementButton?: elementType, incrementButton?: elementType, input?: elementType, root?: elementType }
Default:
{}
The
ref
is forwarded to the root element.Slots
To learn how to customize the slot, check out the Overriding component structure guide.
The component that renders the increment button.
Default: 'button'
Global class: .MuiNumberInput-incrementButton
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverrides
property in a custom theme.
CSS classes
These class names are useful for styling with CSS. They are applied to the root slot when specific states are triggered.