Number input
A number with − and + and the arrow keys, kept between a min and a max.
Up to 12 per table
Installation
npm i @uisatin/uiimport { NumberInput } from '@uisatin/ui/number-input'About 13.4 kB of JavaScript, minified and gzipped, with what it imports (React aside). The stylesheet is one file for every component.
npx shadcn@latest add https://uisatin.dev/r/number-input.jsonAdds number-input.tsx, dropdown.tsx, form-field.tsx, kbd.tsx, labels.tsx, pointer-modality.tsx and select.tsx to components/ui and installs iconoir-react.
First time with Satin? Set it up once, styles and fonts included, with the installation guide.
API Reference
The NumberInput component is a spinbutton: arrow keys step, Page Up / Down step ten times, Home / End jump to the limits; a typed value is clamped and snapped on Enter or blur.
| Prop | Type | Default |
|---|---|---|
value | number | — |
defaultValue | number | 0 |
onValueChange | (value: number) => void | — |
min | number | — |
max | number | — |
step | number | 1 |
size | "sm""md""lg" | "md" |
formatValue | (value: number) => string | — |
label | ReactNode | — |
hint | ReactNode | — |
error | ReactNodeboolean | — |
disabled | boolean | false |
name | string | — |
className | string | — |
ref | Ref<HTMLInputElement> | — |
...props | ComponentProps<'input'>Other attributes go to <input> | — |
Accessibility
The input has role="spinbutton" with aria-valuenow, aria-valuemin, aria-valuemax and aria-valuetext from formatValue, named by label or aria-label. The − and + buttons are named "Decrease" and "Increase", point at the input with aria-controls and are left out of the tab order, since the keys do the same.
| Key | Action |
|---|---|
| ↑or↓ | Steps up or down by step. |
| Page UporPage Down | Steps ten times. |
| HomeorEnd | Jumps to min or max, when set. |
| Enter | Clamps a typed value, snaps it to step and commits it. |
| Esc | Drops what was typed and puts the last value back. |
Something wrong or missing on this page?
Report a problemSuggest an improvement