Demos

A number field with a scrub label and step buttons.

Usage

Use a number field whenever someone types a number, like weight, a dose, or a count. Use it instead of an Input with type="number".

Import it from @workspace/ui/components/number-field.

Anatomy

  • NumberField — The root. Holds the value, limits, and size.
  • NumberFieldScrubArea — The label. Drag it left or right to change the value.
  • NumberFieldGroup — The pill-shaped frame around the buttons and input.
  • NumberFieldDecrement — The minus button.
  • NumberFieldInput — The text input, centred.
  • NumberFieldIncrement — The plus button.

Notes

  • Arrow Up and Arrow Down step by step. Hold Shift for largeStep and Alt for smallStep.
  • Values are clamped to min and max when the field loses focus.
  • Without NumberFieldScrubArea, give NumberFieldInput an aria-label.
  • NumberFieldScrubArea must be inside a NumberField. It throws an error otherwise.

Examples

Sizes

sm, default, and lg. They match the heights of Input.

Decimal format

Set step and format to step by tenths and always show one decimal place.

Controlled

Hold the value with value and onValueChange. The value is null when the input is empty.

Disabled

A number field that cannot be changed.

Props

These are the props you set most often. Unlisted props pass through to the underlying element.

NumberField

PropTypeDefaultDescription
defaultValuenumber—Starting value.
valuenumber or null—Value when controlled.
onValueChange(value) => void—Called when the value changes.
minnumber—Lowest allowed value.
maxnumber—Highest allowed value.
stepnumber or "any"1Amount the buttons and arrow keys change the value by.
smallStepnumber0.1Step with Alt held.
largeStepnumber10Step with Shift held.
formatIntl.NumberFormatOptions—How the value is shown, such as decimal places or units.
size"sm", "default", or "lg"defaultHeight of the field.
disabledbooleanfalseBlocks input and dims the field.
namestring—Field name for form submission.

NumberFieldScrubArea

PropTypeDefaultDescription
labelstring—Required. The label text, linked to the input.