Skip to content

Number Input

A number input with stepper buttons, formatting and a draggable label.

Installation

  1. Add the registryOnce per project
  2. Add number-input

Usage

A FieldLabel in the same Field labels the input. Without a visible label, give NumberInput an aria-label.

Without children, NumberInput renders its input and stepper buttons. To customize them, such as to put a currency symbol before the number or a NumberInputScrubArea around the label, compose the parts yourself:

Either way, NumberInput passes its aria-label and placeholder to its NumberInputInput.

Composition

Examples

Formatting

format takes Intl.NumberFormat (opens in a new tab) options, for decimals, percentages or units.

$

Scrub area

Wrap the label in a NumberInputScrubArea to change the value by dragging it sideways.

px

Large

Set size="lg" on NumberInput for a taller input, or size="sm" for a shorter one.

$

Steppers on either side

Put NumberInputDecrement before NumberInputInput to place the buttons on either side of the value. To center the value with a label after it, size the input to its value with field-sizing-content, and push the buttons to the edges with mr-auto and ml-auto. In browsers without field-sizing, the input's size attribute sets its width in characters.

seats

Display

Set variant="display" to show the value in large type between round stepper buttons, for a Sheet or Card built around a single number. To label the number, compose the parts and add a caption under NumberInputInput.

cups per day

Disabled

Read-only

Invalid

Set invalid on the Field and explain the problem with a FieldError.

Props

Base UI's styling (opens in a new tab) and composition (opens in a new tab) guides say more about className, style and render.

NumberInput

NumberInputGroup

NumberInputInput

NumberInputDecrement

NumberInputIncrement

NumberInputScrubArea