Stepper

A number field with the small up and down arrows beside it, stepped by clicks, held arrows and the keyboard.

Installation

pnpm dlx shadcn@latest add @cupertinoui/stepper

The first install also adds the macOS theme. See Installation to set up the registry.

Usage

import { Stepper, StepperButtons, StepperInput } from "@/components/ui/stepper"

<Stepper defaultValue={4} min={1} max={8}>
  <StepperInput aria-label="Tab width" />
  <StepperButtons />
</Stepper>
Up and Down step the value, Page Up and Page Down step it by 10, and holding an arrow button keeps stepping. The arrows aren't separate stops for Tab, as on macOS.

Examples

Sizes

Regular beside a 24pt text field, and small beside a 20pt one for inspectors.

Formatting

format takes Intl.NumberFormat options: a percentage that steps by 5%, and degrees that step by 15.

API Reference

Every part forwards the props of the underlying Base UI Number Field part. The props below are the ones CupertinoUI adds or changes.

Stepper

Base UI's Number Field root: also value, onValueChange, disabled, name and the other Number Field props.

PropTypeDescription
size"sm" | "default"
Default: "default"
Small for inspectors, regular for windows.
defaultValuenumberThe starting value, when uncontrolled.
min / maxnumberThe range the value stays in.
stepnumber
Default: 1
How much an arrow click or key press changes the value.
formatIntl.NumberFormatOptionsHow the field shows the value, e.g. as a percentage.
classNamestringExtra classes, merged with the component's own.

StepperInput

The number field, right-aligned with tabular figures.

PropTypeDescription
classNamestringExtra classes, merged with the component's own.

StepperButtons

The up and down arrows on a capsule. Leave out StepperInput for arrows alone.

PropTypeDescription
classNamestringExtra classes, merged with the component's own.