Quantity
Press the plus, hold it to run, or type. Arrow keys step, Shift or PageUp / PageDown jump ten, Home and End go to the ends. At 10 the plus has nothing left and rattles the box.
A number you can nudge: minus, the value, plus. One hand-drawn box with a tick before each button, the number in script, buttons that repeat while you hold them, arrow keys and PageUp / PageDown for the keyboard, and a rattle of the box when there is nowhere left to go. The value is a real text input, so it types, pastes and submits with a form.
npx shadcn@latest add @wobko/stepperFirst time here? Add the registry to components.json first. How to install
Press the plus, hold it to run, or type. Arrow keys step, Shift or PageUp / PageDown jump ten, Home and End go to the ends. At 10 the plus has nothing left and rattles the box.
A step of 0.5 on a price (no float drift, shown with two places), a temperature in whole degrees with the wheel opt-in (click into it and scroll), and a value that snaps to multiples of five.
The stepper in a cart: each line counts its quantity in tally marks next to the number, the total follows, and a line at zero says so. The tally is decoration; the number is the truth.
name puts the number in FormData; required refuses an empty field (a blank is put back); Reset returns an uncontrolled stepper to its default. The third one is invalid, the fourth disabled.
The control (`role="group"`, the drawn box). Without children it is `StepperDecrement`, `StepperInput` and `StepperIncrement`; compose your own to add a `StepperTally` or other parts. Uncontrolled (`defaultValue`) or controlled (`value` + `onValueChange`; `value={undefined}` is a controlled, empty field). The value is a number, or `undefined` while the field is empty (NaN and Infinity count as empty, never the text "NaN").
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue / onValueChange | number | undefined | - | The value. `onValueChange` fires when a button, key, wheel step or typed number (read on Enter or blur) changes it. |
| min / max | number | - | Bounds. Steps and typed numbers are clamped; a button with nothing left is `aria-disabled` (not `disabled`, so focus is not lost) and rattles the box when pressed. |
| step | number | 1 | The size of a button press or an arrow key. Zero, negative or not a number falls back to 1. |
| largeStep | number | 10 x step | Shift + arrows and PageUp / PageDown. |
| snap | boolean | false | Round typed and stepped values to multiples of `step` counted from `min` (or 0). |
| precision | number | - | Decimal places to show and round to. Default: the most places the step, the minimum and the current value have, so 0.1 steps do not drift. |
| format / parse | (n: number) => string / (text: string) => number | undefined | - | How the number is shown and read back: currency, units. The default reader takes a dot or a comma as the point, both together ("1,234.5", "1.234,5" are 1234.5), a repeated separator as thousands ("1,234,567"), and Eastern Arabic and Persian digits. A lone "1,234" is 1.234: with one separator there is no telling a decimal comma from a thousands comma, so pass `parse` for your locale. A `parse` that answers NaN puts the last good value back. |
| wheel | boolean | false | The mouse wheel steps the number while it has focus (and stops the page scrolling). Off by default: a wheel that changes values under a scrolling page is a trap. |
| id / name / form / required | - | Go to the number's input: `id` for a Label, `name` and `form` for forms (with a `format`, a hidden input carries the plain number and the shown text is only the display), `required` forbids an empty field. | |
| aria-label / aria-labelledby / aria-describedby | string | - | Names for the number (the spinbutton), not for the group. |
| disabled / readOnly / invalid | boolean | - | Dashed pencil on a wash / a value that is shown but not changed / the red pencil box. |
| seed | string | number | - | Pins the hand: the same seed always draws the same box. |
The value as tally marks (four strokes and a slash to a group), a companion for a quantity you count on your fingers. Decorative (`aria-hidden`).
| Prop | Type | Default | Description |
|---|---|---|---|
| max | number | 20 | How many marks to draw at most. |
The files the CLI copies into your project.
Loading the source