Number Input
ProNewA number field with steppers that repeat while held, arrow-key stepping, locale formatting and a label you can drag to scrub.
Installation
pnpm dlx shadcn@latest add @viewport/number-input
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
| Prop | Type | Default |
|---|---|---|
| value | number | null | — |
| defaultValue | number | null | null |
| onValueChange | (value: number | null) => void | — |
| min | number | — |
| max | number | — |
| step | numberThe amount one press, arrow key or scrub step changes the value by. Shift multiplies it by ten. | 1 |
| format | Intl.NumberFormatOptionsHow the value is shown while the field is not being edited, e.g. `{ style: "currency", currency: "USD" }`. | — |
| locale | string | — |
| scrubLabel | React.ReactNodeA short label at the start of the field that can be dragged sideways to change the value, e.g. "W". | — |
| suffix | React.ReactNodeA unit shown after the number, e.g. "px". Not part of the value. | — |
Accessibility
- A spinbutton with min, max, current value and a formatted value text.
- Arrow keys step, Shift steps by ten, Page Up and Down, Home and End.
- Clamps when you leave the field, not while you type.
- The stepper buttons are skipped by Tab; the keyboard uses the field.