Skip to contentSkip to content

NumberField API

API reference docs for the React NumberField component. Learn about the props, CSS, and other APIs of this exported module.

Demos

Import

import NumberField from '@mui/material/NumberField';
// or
import { NumberField } from '@mui/material';

Learn about the difference by reading this guide on minimizing bundle size.



Number fields let users enter, format, and adjust numeric values.

Props

Props of the FormControl component are also available.

NameTypeDefaultDescription
allowOutOfRangeboolfalse

If true, values entered by typing or pasting are not clamped to min and max. Stepping with the buttons, keyboard, mouse wheel, or scrub area still respects the bounds.

allowWheelScrubboolfalse

If true, the mouse wheel adjusts the value while the input is focused and hovered.

autoFocusboolfalse

If true, the input element is focused during the first mount.

classesobject-

Override or extend the styles applied to the component.

See CSS classes API below for more details.

color'primary'
| 'secondary'
| 'error'
| 'info'
| 'success'
| 'warning'
| string
'primary'

The color of the component. It supports both default and custom theme colors, which can be added as shown in the palette customization guide.

controlsPosition'end'
| 'split'
| 'stacked'
| false
'end'

The arrangement of the control buttons. Use 'end' for horizontal minus/plus buttons at the end, 'split' for a minus button at the start and a plus button at the end, 'stacked' for up/down chevrons at the end, or false for no control buttons.

defaultValuenumber-

The initial numeric value for an uncontrolled field. Omit this prop to start with an empty field. Use value for a controlled field.

disabledboolfalse

If true, the component is disabled.

endAdornmentnode-

Content displayed immediately after the input, such as a unit or a clear button.

errorboolfalse

If true, the field is displayed in an error state.

formstring-

The id of the form that owns the field. Use this prop when the field is rendered outside the form.

formatobject-

The Intl.NumberFormat options used to format the displayed value. The value prop and value callbacks use numbers or null, regardless of the display format.

fullWidthboolfalse

If true, the input will take up the full width of its container.

helperTextnode-

The helper text content.

idstring-

The id of the visible input, used to associate its label and helper text. If omitted, an ID is generated.

inputReffunc
| { current?: object }
-

A ref to the visible <input> element.

labelnode-

The label content.

largeStepnumber10

The amount to increment or decrement while holding the Shift key.

localeArray<object
| string>
| object
| string
-

The locale or locales used to format and parse the value. Defaults to the runtime's locale.
See Intl.NumberFormat.

maxnumber-

The upper bound for the numeric value. The increment button is disabled at or above this value.

minnumber-

The lower bound for the numeric value. The decrement button is disabled at or below this value.

namestring-

Identifies the field when a form is submitted. The submitted value is the unformatted number.

onBlurfunc-

Callback fired when the input loses focus.

onFocusfunc-

Callback fired when the input receives focus.

onValueChangefunc-

Callback fired when the numeric value changes. Call eventDetails.cancel() to reject the proposed change.

Signature:function(value: number | null, eventDetails: object) => void
  • value The new numeric value, or null when the input is empty.
  • eventDetails The interaction details, including the native event and a reason: "input-change", "input-clear", "input-blur", "input-paste", "keyboard", "increment-press", "decrement-press", "wheel", "scrub", or "none".
onValueCommittedfunc-

Callback fired when the value is committed. Direct text entry commits on blur. Pointer presses on the stepper buttons and scrub interactions commit on pointer release. Keyboard and wheel changes commit immediately.

Signature:function(value: number | null, eventDetails: object) => void
  • value The committed numeric value, or null when the input is empty.
  • eventDetails The interaction details, including the native event and a reason: "input-blur", "input-clear", "keyboard", "increment-press", "decrement-press", "wheel", "scrub", or "none".
placeholderstring-

The short hint displayed in the input when it is empty.

readOnlyboolfalse

If true, the value cannot be changed through user interaction. The input can still receive focus.

renderelement
| func
-

Replaces the root element while preserving its styles and behavior. Accepts an element or a function that receives the root props and Base UI state.

requiredboolfalse

If true, a value is required for form submission and the label is marked as required.

scrubAreaPosition'end'
| 'start'
| false
false

The placement of the drag handle used to adjust the value. Use 'start' or 'end' to show the handle, or false to hide it. Its position is independent of controlsPosition.

size'medium'
| 'small'
| string
'medium'

The size of the component.

slotProps{ controls?: func
| object, decrementButton?: func
| object, formHelperText?: func
| object, htmlInput?: func
| object, incrementButton?: func
| object, input?: func
| object, inputLabel?: func
| object, root?: func
| object, scrubArea?: func
| object, scrubAreaCursor?: func
| object }
{}

The props used for each slot inside.

slots{ controls?: elementType, decrementButton?: elementType, formHelperText?: elementType, htmlInput?: elementType, incrementButton?: elementType, input?: elementType, inputLabel?: elementType, root?: elementType, scrubArea?: elementType, scrubAreaCursor?: elementType }{}

The components used for each slot inside.

smallStepnumber0.1

The amount to increment or decrement while holding the Alt key (Option on macOS).

snapOnStepboolfalse

If true, stepping snaps the value to intervals starting at min, or 0 if min is omitted. Modifier keys use the corresponding smallStep or largeStep intervals.

startAdornmentnode-

Content displayed immediately before the input, such as a currency symbol.

step'any'
| number
1

The amount to increment or decrement with the buttons, arrow keys, mouse wheel, or scrub area. Set min explicitly to enable step validation on form submission. Set to "any" to disable step validation; interactive stepping then uses 1, while the Alt and Shift keys still use smallStep and largeStep.

sxArray<func
| object
| bool>
| func
| object
-

The system prop that allows defining system overrides as well as additional CSS styles.

See the `sx` page for more details.

valuenumber-

The controlled numeric value. Use null to display an empty field and onValueChange to update the value.

variant'filled'
| 'outlined'
| 'standard'
'outlined'

The variant to use.

The ref is forwarded to the root element.

Inheritance

While not explicitly documented above, the props of the FormControl component are also available in NumberField. You can take advantage of this to target nested components.

Theme default props

You can use MuiNumberField to change the default props of this component with the theme.

Slots

Slot nameClass nameDefault componentDescription
controls.MuiNumberField-controlsInputAdornmentThe component that renders each group of stepper buttons.
decrementButton.MuiNumberField-decrementButtonIconButtonThe component that renders the decrement button.
formHelperText.MuiNumberField-formHelperTextFormHelperTextThe component that renders the helper text.
htmlInput.MuiNumberField-htmlInput'input'The component that renders the native input element. Use & .MuiNumberField-htmlInput in styleOverrides.root to style it.
incrementButton.MuiNumberField-incrementButtonIconButtonThe component that renders the increment button.
input.MuiNumberField-inputOutlinedInputThe component that renders the Material input wrapper.
inputLabel.MuiNumberField-inputLabelInputLabelThe component that renders the input's label.
root.MuiNumberField-rootFormControlThe component that renders the root. While scrubbing, the root has the MuiNumberField-scrubbing class. Use &.MuiNumberField-scrubbing in styleOverrides.root to style that state.
scrubArea.MuiNumberField-scrubArea'span'The component that renders the drag handle for adjusting the value.
scrubAreaCursor.MuiNumberField-scrubAreaCursor'span'The component that renders the custom cursor while dragging the scrub area.

CSS classes

These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.

Class nameRule nameDescription
.MuiNumberField-endAdornmentendAdornmentStyles applied to the wrapper around the end adornment content.
.MuiNumberField-startAdornmentstartAdornmentStyles applied to the wrapper around the start adornment content.

You can override the style of the component using one of these customization options:

Source code

If you did not find the information in this page, consider having a look at the implementation of the component for more detail.