Number Stepper

A number with − and +: hold to repeat, type, arrow keys, currency and percent.

Category
Forms
Access
Free with an account
Source
235 lines · one file
States
6 drawn

The decision inside it

Nothing is clamped mid-keystroke

Typing 120 into a field with a minimum of 10 does not turn the 1 into 10. The text is read when you leave the field or press Enter, then clamped, snapped to the step and formatted.

When to use it

Use Number Stepper for a small whole quantity people nudge up and down: seats, guests, copies. Give it min, max and step, and formatOptions for currency or percent. For a wide range, use Slider.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Number Stepper for this.
Install it: npx shadcn@latest add @liro/number-stepper
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/number-stepper.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/seat-picker.tsx
import { NumberStepper } from "@/components/ui/number-stepper";

export function SeatPicker({ seats, setSeats }: { seats: number; setSeats: (n: number) => void }) {
  return <NumberStepper aria-label="Seats" value={seats} onValueChange={setSeats} min={1} max={50} />;
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
valuenumber NoThe number. Controlled.
defaultValuenumber NoThe starting number when uncontrolled. Default min, or 0.
onValueChange(value: number) => void NoCalled with each new number, already clamped and snapped.
minnumber NoLowest allowed.
maxnumber NoHighest allowed.
stepnumber NoHow much one press moves. Default 1.
formatOptionsIntl.NumberFormatOptions NoHow the number is shown, e.g. { style: "currency", currency: "USD" }.
allowInputboolean NoAllow typing in the middle. Default true.
size"sm" | "md" Nosm 32px or md 36px tall. Default md.
disabledboolean No–
namestring NoThe field's name inside a form.
idstring No–
classNamestring No–

Dependencies

npm packages

clsxlucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-themefield

States

All of them are drawn by the component. None is left for you to design.

  • Default
  • At minimum
  • Currency
  • Percent
  • Buttons only
  • Disabled

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances