Number Input
A number input with increment/decrement buttons and min/max/step support.
Default
With Step
With Min/Max Bounds
Disabled
Invalid
With Field
Installation
npx visor add number-inputThis copies two files into your project:
components/ui/number-input/number-input.tsx— the componentcomponents/ui/number-input/number-input.module.css— the styles
Usage
import { NumberInput } from '@/components/ui/number-input/number-input';
<NumberInput defaultValue={1} min={0} max={10} />Prefix and suffix
Same props, same treatment as Input: a currency symbol before the value, a unit after it, inside the same well as the steppers.
Skin and Glass
A theme reshapes the field and its buttons through the number-input hooks: fill,
focused fill, edge colour, corners, height, the value's width, size and weight, and
the buttons' size, inset, corners, ink, hover fill and icon size. Each falls back to
the look above, so a theme that binds none of them draws NumberInput unchanged. The
full list is on Component Tokens.
components:
number-input:
height: "54px"
radius: "12px"
value-width: "72px"
value-font-size: "22px"
value-font-weight: "640"
button-size: "40px"
button-inset: "7px"
button-radius: "50%"
icon-size: "20px"Glass is off by default. Inside data-glass="on" (see Glass),
the field takes the glass layer's control values: its fill, a brighter fill on focus,
its ring as the edge, its ink and its blur. Everywhere else the field is solid.
In Five Looks
NumberInput as shipped, and with the sizes above, in each look on the theme picked in the docs. The Photo looks turn glass on over a photo.
API Reference
NumberInputProps
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | — | Controlled numeric value. |
defaultValue | number | — | Default value for uncontrolled usage. |
onChange | (value: number | undefined) => void | — | Callback when the value changes. |
min | number | — | Minimum allowed value. |
max | number | — | Maximum allowed value. |
step | number | 1 | Increment/decrement step size. |
disabled | boolean | false | Disables the number input and buttons. |
Accessibility
- Always provide an
aria-labelor pair with a<Label>usinghtmlFor/id— the component has no visible label by default - The buttons have
aria-label="Decrease value"andaria-label="Increase value", and stay out of the tab order: the keyboard steps the value instead - The input renders as
type="text"withinputmode="numeric"for appropriate mobile keyboard - Keyboard: ArrowUp and ArrowDown step the value by
step, holding atminandmax. A caller'sonKeyDownruns first and can cancel the step withpreventDefault() - From empty, the first press of either button lands on
minwhen one is set min/maxbounds are enforced both visually (buttons disable at bounds) and on input blur