# Stepper input

> A tactile incrementer: tap to step, hold to accelerate, bounds give an elastic bumper shake, and digits roll in place.

Number inputs usually force manual typing or rely on tiny browser stepper arrows that ignore your theme and lack feel. This is a tactile hairline stepper: single taps roll the odometer in the direction of change; holding down a button begins with a measured 300ms pause before accelerating smoothly down to 30ms intervals with scaled steps. Reaching min or max limits disables the trigger and produces an elastic bumper shake. Clicking the middle opens a clean inline input that parses, clamps, and commits on blur or Enter.

## Install

```bash
npx shadcn@latest add @hairline/stepper-input
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): `number-roll`
- Docs and live preview: https://hairlineui.com/ui/stepper-input
- Registry item (source): https://hairlineui.com/r/stepper-input.json

## Usage

```tsx
import { StepperInput } from "@/components/stepper-input";

<StepperInput
  label="Workspace seats"
  defaultValue={5}
  min={1}
  max={50}
  unit="seats"
  onValueChange={(seats) => updateSeats(seats)}
/>
```

## Team seat checkout with live pricing

StepperInput controls team seat allocation with minimum and maximum thresholds. Value updates roll instantly and feed directly into cost calculation.

```tsx
// app/billing/seats-calculator.tsx
"use client";

import * as React from "react";
import { StepperInput } from "@/components/stepper-input";
import { NumberRoll } from "@/components/number-roll";

const PRICE_PER_SEAT = 15;

export function SeatsCalculator() {
  const [seats, setSeats] = React.useState(5);
  const total = seats * PRICE_PER_SEAT;

  return (
    <div className="flex items-center justify-between rounded-xl border border-border p-4">
      <div>
        <p className="text-sm font-medium text-foreground">Team seats</p>
        <p className="text-xs text-muted-foreground">$15 / seat / month</p>
      </div>

      <div className="flex items-center gap-4">
        <StepperInput
          label="Seats"
          value={seats}
          min={1}
          max={100}
          unit="seats"
          onValueChange={setSeats}
        />
        <div className="min-w-[4.5rem] text-right font-mono text-sm font-medium text-foreground">
          <NumberRoll value={total} prefix="$" />
          <span className="text-xs text-muted-foreground">/mo</span>
        </div>
      </div>
    </div>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | – | Accessible name for the stepper, announced to assistive technologies. |
| `value` | `number` | – | The controlled numeric value. |
| `defaultValue` | `number` | `0` | Initial numeric value when uncontrolled. |
| `onValueChange` | `(value: number) => void` | – | Callback invoked when the value changes. |
| `min` | `number` | `-Infinity` | Minimum allowed value. |
| `max` | `number` | `Infinity` | Maximum allowed value. |
| `step` | `number` | `1` | Amount to increment or decrement on single steps. |
| `largeStep` | `number` | – | Step multiplier for PageUp/PageDown and sustained acceleration (defaults to step * 10). |
| `unit` | `string` | – | Optional text suffix displayed beside the value (e.g. "seats", "px", "%"). |
| `format` | `Intl.NumberFormatOptions` | – | Formatting options forwarded to NumberRoll. |
| `variant` | `"pill" \| "field"` | `"pill"` | Border radius style: pill (rounded-full) or field (rounded-lg). |
| `size` | `"sm" \| "default"` | `"default"` | Control height and typography size: sm (28px) or default (36px). |
| `disabled` | `boolean` | `false` | Disables all interactions and dims the control. |
| `name` | `string` | – | Name attribute for hidden input submitted with HTML forms. |

## States

- **rest**: Hairline pill or field container in rest state. Decrement and increment buttons display quiet icons with disabled styling when at bounds.
- **tap**: Single tap or click advances by one step. The digit rolls in the direction the value changed over 260ms.
- **accelerate**: Holding down past 300ms activates rapid stepping, ramping up to 30ms tick intervals with large-step multipliers.
- **limit shake**: Attempting to step past min or max triggers an elastic bumper shake (±3px over 280ms) and disables the button.
- **direct edit**: Clicking the value swaps the odometer for an active text input; Escape cancels back to original value, Enter commits clamped number.

## What it handles

Building a custom number stepper seems trivial until you need hold-to-accelerate timing, bound checking, keyboard arrow accessibility, decimal precision rounding, and seamless direct text editing. This handles all of it.

- **Odometer roll direction**: Increments roll upward and decrements roll downward through NumberRoll, maintaining continuous directional feedback.
- **Exponential hold acceleration**: Holds start with a 300ms delay to prevent accidental runs, then step at 90ms, 55ms, and 30ms with automatic 5x/10x multipliers.
- **Elastic bumper feedback**: Hitting the min or max bound produces a brief horizontal elastic shake rather than dead-ending without feedback.
- **Direct editing in place**: Clicking the number reveals a full input without shifting a pixel; Enter or blur parses, clamps, and commits.
- **Floating-point precision**: Handles fractional steps like 0.1 or 0.05 without standard JavaScript floating-point artifacts like 0.30000000000000004.
- **Accessible spinbutton**: Supports ArrowUp/Down, PageUp/Down for large steps, and Home/End for boundary limits, with polite screen-reader announcements.

## Replaces

native <input type="number">, custom setInterval loops, boundary clamping logic, direct text parsing, odometer sync, keyboard spinbutton handlers

## Where it fits

- **Billing & seats**: Adjust workspace licenses or team member counts with immediate price calculations.
- **Canvas & design inspectors**: Nudge padding, border-radius, font size, or opacity with hold-to-accelerate speed.
- **E-commerce carts**: Quantity steppers that prevent zero-quantity mistakes and clamp to warehouse inventory.
- **Model parameters**: Tune temperature, top-p, and context window limits with fine-grained decimal steps.

## Notes

- Uses NumberRoll internally so numbers roll in the exact direction of travel (increment rolls up, decrement rolls down).
- Hold-to-accelerate uses touch-safe pointer listeners and clears all timers on pointer cancel or unmount.
- Arrow keys, PageUp/PageDown, and Home/End support the full WAI-ARIA spinbutton specification.
- Direct text edit automatically clamps and rounds to the specified step precision to eliminate floating-point arithmetic errors.
- Reduced motion replaces the bumper shake and roll animations with instant updates.

License: MIT (https://hairlineui.com/license#components)
