Number Input
A numeric stepper whose digits roll into place. Hold to repeat, arrow keys, Intl formatting and a polite shake at the bounds.
Hold a button to repeat. Arrow keys work too, Shift for steps of 10.
Playground
Tweak the props, the preview and the code follow.
<NumberInput
defaultValue={4}
min={0}
max={20}
/>Installation
npx @plumsydev/plum-ui add number-inputAlso pulls in animated-number automatically.
Usage
import { NumberInput } from "@/components/ui/number-input"<NumberInput defaultValue={3} min={1} max={10} />Examples
Formats
Any Intl.NumberFormat options: currency, percent, units.
Cart
Quantities driving an animated total.
Heavyweight hoodie
Charcoal · L · $89
Six-panel cap
Ecru · $34
Merino socks
3-pack · $24
Sizes
API Reference
NumberInput
Extends the native input, minus type, value and onChange.
| Prop | Type | Default |
|---|---|---|
valueControlled value. | number | — |
defaultValueInitial value when uncontrolled. | number | 0 |
onValueChangeCalled with the clamped, step-rounded value. | (value: number) => void | — |
min / maxBounds. Hitting them shakes the field. | number | -Infinity / Infinity |
stepIncrement. Shift multiplies by 10 from the keyboard. | number | 1 |
formatHow the value is displayed when not focused. | Intl.NumberFormatOptions | — |
sizeHeight. | "sm" | "default" | "lg" | "default" |
hideControlsHide the − and + buttons. | boolean | false |
containerClassNameClasses for the outer wrapper. | string | — |
Notes
- Exposes
role="spinbutton"witharia-valuenow,aria-valueminandaria-valuemax. - Home and End jump to
minandmaxwhen they are finite. Typing a value commits on Enter or blur.