Number Input

A field for numbers. The buttons and the arrow keys step the value, and it stays within min and max.

General

Name the field with aria-label, or with a label passed as children.

Step and precision

step sets how much each click or arrow adds. The value keeps the decimal places of step, or the ones set in precision.

Without controls

Hide the buttons with hideControls. The arrow keys still step the value.

Error

Show a message with error and errorMessage. Say what happened and how to fix it.

Controlled

onChange receives the number, or null when the field is empty.

Disabled and read only

APIs

NumberInput.Props

AttributeDescriptionTypeAccepted valuesDefault
valuethe number, to control the fieldnumber / null--
initialValuethe number at the startnumber / null-null
onChangecalled with the number, or null when the field is empty(value: number | null) => void--
minlowest valuenumber--
maxhighest valuenumber--
stephow much a button or an arrow key addsnumber-1
precisiondecimal places keptnumber-the ones of step
typecolor of the fieldNormalTypes'default', 'primary', 'secondary', 'success', 'warning', 'error', 'info'default
hideControlshide the buttonsboolean-false
errormark the value as invalidboolean-false
errorMessagetext shown below the field with errorstring--
disableddisable the fieldboolean-false
readOnlyshow the value without letting it changeboolean-false
childrenlabel shown above the fieldReactNode--
...native props, passed to the inputInputHTMLAttributes'aria-label', 'name', 'placeholder', ...-

Typing and limits

The field accepts digits, a minus sign and one decimal separator, a dot or a comma. While the user types, onChange receives the number as it is. When the field loses the focus, the value is kept within min and max and rounded to precision. The buttons and the keys never go past the limits.

Ref

The ref points at the input.

Accessibility

The input has role="spinbutton" with aria-valuenow, aria-valuemin and aria-valuemax. The buttons are named Increase and Decrease and stay out of the tab order, since the keys do the same from the input. With error, the input has aria-invalid and is described by the message.

KeyAction
Arrow Up and DownAdd or subtract step
Page Up and DownAdd or subtract ten steps
Home and EndGo to min or max, when set
Edit this page on GitHub