- Implementation
- NumberField Props
Common Examples
Default values
A default value can given toNumberField to use the field in an uncontrolled mode.Controlled usage
TheNumberField can be controlled. This means you can maintain the state outside the component. Listen for new values with onChange and supply state back into the value prop.Empty
TheNumberField allows not only 0, but also the ability for the input to be completely cleared out. This is represented by null in the onChange, value, and defaultValue props.Step value
The increment and decrement functionality of theNumberField defaults to adding or subtracting 1, but can be modified to add or subtract another number. This value applies to the visual +/- buttons as well as keyboard up/down keys.Note that step does not enforce that the value is a multiple of the step. Instead, it will add to or subtract from the current value.Min and max values
TheminValue and maxValue props define the bounds of the NumberField. The stepper buttons and keyboard up/down keys clamp the value between minValue and maxValue: if value + step > maxValue, the result of incrementing is maxValue, and if value - step < minValue, the result is minValue.Negative values
TheNumberField defaults to a minimum of 0, but supports negative number inputs by setting a lower minValue.Fractional values
TheNumberField defaults to integers, but supports decimal number inputs with the maximumFractionDigits and minimumFractionDigits props.Hiding increment/decrement buttons
The +/- buttons can be optionally hidden using thehideControls prop. When hidden, users can still change the value by typing directly into the input or using keyboard up/down arrow keys.Errors
Error messages can be applied to the component via theerror prop.Markdown in labels
Thelabel prop supports inline markdown: bold (**text**), italic (*text*), bold and italic (***text***), highlight (==text==), and code (`text`).Hide the label
UsehideLabel to visually hide the label. The label string is converted to an aria-label on the input so it remains accessible to screen readers — any inline markdown is stripped to plain text.