# Stepper

> Stepper and Step show progress through a sequence as an ordered list, with keyboard-selectable steps, linear mode, read-only mode, orientation, label placement, statuses and custom step rendering.

Canonical: https://salmonui.dev/docs/navigation/stepper

```tsx
import { Step, Stepper } from '@salmonui/navigation/stepper';
import '@salmonui/navigation/stepper/styles.css';

const [step, setStep] = useState(0);

<Stepper aria-label="Checkout" value={step} onValueChange={setStep} linear>
  <Step label="Account" description="Sign in" />
  <Step label="Billing" optional />
  <Step label="Confirm" invalid={errors.confirm} />
</Stepper>
```

`@salmonui/navigation/stepper` is self-contained: it imports no other family, and
its stylesheet needs only the theme variables. The Stepper is an indicator:
which content a step shows is up to the page (or a `Tabs` with a hidden tab
list).

## Steps

Each `Step` has `label`, `description`, `icon` (replaces the step
number), `optional` (shows "Optional"), `disabled`, `invalid` (marks
a step whose fields fail validation; the Stepper does not validate) and
`status`. `className` and `style` reach the `<li>`, other attributes too; on
`Stepper` they reach the `<ol>`, which is also the `ref`. Steps are
the direct children of `Stepper` (arrays are fine).

## Active step and events

`value` / `defaultValue` / `onValueChange` hold the 0-based active step.
A click or Enter / Space on a step calls `onStepClick({ index,
source })`, then `onBeforeValueChange({ value, previousValue,
source })`, whose `preventDefault()` cancels the change, then
`onValueChange(value, { source })`. Without `value` the Stepper is uncontrolled and starts at
`defaultValue` (default `0`); with `value`, as in the example above, only
the prop moves the active step.

The Stepper has no next, previous, reset or refresh methods: the
active step is a prop, so methods would let the Stepper and the application
state disagree, and the connectors are CSS that never needs a refresh. Next
and previous buttons set `value` (`step + 1`, `step - 1`, `0` to reset).

## Status and connectors

Without `status`, a step before the active one is `completed`, the active
one `inProgress` and later ones `notStarted`. The status is the
`data-status` attribute: the indicator shows a check when completed and `!`
when invalid, and the connector line after a completed step is filled, all
in CSS.

## Modes

- `linear`: only earlier steps and the next one are selectable;
  later steps are `aria-disabled`.
- `readOnly`: the steps are plain content, not buttons.
- `orientation: 'horizontal' | 'vertical'` and
  `labelPlacement: 'top' | 'bottom' | 'start' | 'end'` (default
  `'bottom'` horizontally and `'end'` vertically). `start` and `end` are
  logical and follow `dir`.
- There is no step type prop: the `Step` content already says what
  a step shows. Omit `label` for indicator-only steps; for label-only steps,
  hide the indicator with CSS on `.salmon-stepper-indicator` or use
  `renderStep`; omit `icon` for the numbered indicator.

## Custom rendering

`renderStep(context)` replaces the content of every step. The
context is `{ index, status, active, label, description, icon, optional,
invalid, disabled }`; it is called during render for each step, so it also
covers per-step render customization without a separate event. A `Step` with children renders those instead, for one step.

## Keyboard and ARIA

The Stepper renders an `<ol>`; the active step has `aria-current="step"`.
Selectable steps are buttons with one tab stop:

| Key | Action |
| --- | --- |
| ArrowRight / ArrowLeft (horizontal, mirrored in RTL), ArrowDown / ArrowUp (vertical) | Next / previous enabled step |
| Home / End | First / last enabled step |
| Enter, Space | Select the focused step |

Disabled steps are `aria-disabled` and skipped by the arrow keys. Completed
and invalid steps include a visually hidden "Completed" / "Error" text.

## Locale

`localeText` overrides `{ optional, invalid, completed }`; the defaults are
`STEPPER_DEFAULT_LOCALE_TEXT`.

## Styling

`.salmon-stepper` (`data-orientation`, `data-label-placement`,
`data-readonly`), `.salmon-stepper-step` (`data-status`, `data-active`,
`data-invalid`, `data-optional`, `data-disabled`),
`.salmon-stepper-step-button`, `.salmon-stepper-indicator`,
`.salmon-stepper-text`, `.salmon-stepper-label`,
`.salmon-stepper-description`, `.salmon-stepper-optional`. The connector is
the step's `::after`.

## Step tooltips

A step tooltip, plain or templated, is a `Tooltip` from `@salmonui/overlays/tooltip` around the step's trigger. `Step`
`render` receives the trigger props the Stepper computed (`type`,
`className`, `tabIndex`, `aria-disabled`, `onClick`, `children`); spread
them, then the Tooltip's trigger props:

```tsx
import { Step, Stepper } from '@salmonui/navigation/stepper';
import { Tooltip } from '@salmonui/overlays/tooltip';
import '@salmonui/navigation/stepper/styles.css';
import '@salmonui/overlays/tooltip/styles.css';

<Stepper aria-label="Checkout">
  <Step
    label="Cart"
    render={(step) => <Tooltip content="Review the items in your cart" render={(tip) => <button {...step} {...tip} />} />}
  />
  <Step label="Address" render={(step) => <button {...step} title="Where we ship to" />} />
</Stepper>
```

The trigger props hold no focus or pointer handlers (the Stepper tracks
focus on the step's `<li>`), so the two sets never collide. The Tooltip
shows on hover and keyboard focus and closes on Escape, blur or leaving the
step; its content is any `ReactNode`, so a template is just markup. The
Stepper does not import the Tooltip: a Stepper without tooltips does not
pay for one. For a zero-cost hint, put a native `title` on the trigger (as
on "Address"). In a read-only Stepper the trigger is a `<span>` that is not
focusable, so its tooltip appears on hover only; put essential information
in the `description`.

## Server rendering

The Stepper reads no layout: statuses, connectors and the roving tab stop
follow from the props, so the server markup equals the client tree and
hydrates without warnings.

## API reference

[`@salmonui/navigation/stepper`](https://salmonui.dev/docs/reference/navigation/stepper): `Stepper`,
`Step`, `STEPPER_DEFAULT_LOCALE_TEXT` and the context, event and locale
types.

### Live demo: Stepper

Live demo: https://salmonui.dev/demos/navigation/stepper-basics

A controlled linear Stepper driven by Back / Next buttons, with a description, an optional step and an invalid step.

`Demo.tsx`:

```tsx
'use client';
import { useState } from 'react';
import { Button } from '@salmonui/buttons/button';
import { Checkbox } from '@salmonui/inputs/checkbox';
import { Step, Stepper } from '@salmonui/navigation/stepper';
import { Tooltip } from '@salmonui/overlays/tooltip';

export default function StepperBasicsDemo() {
  const [step, setStep] = useState(0);
  const [linear, setLinear] = useState(true);
  const [billingInvalid, setBillingInvalid] = useState(false);
  const steps = ['Account', 'Billing', 'Shipping', 'Confirm'];
  return (
    <div style={{ display: 'grid', gap: 16 }}>
      <Stepper aria-label="Checkout" value={step} onValueChange={setStep} linear={linear}>
        <Step label="Account" description="Sign in" render={(step) => <Tooltip content="Sign in or create an account" render={(tip) => <button {...step} {...tip} />} />} />
        <Step label="Billing" invalid={billingInvalid} />
        <Step label="Shipping" optional />
        <Step label="Confirm" render={(step) => <button {...step} title="Check the order before paying" />} />
      </Stepper>
      <div style={{ display: 'flex', gap: 12, alignItems: 'center', flexWrap: 'wrap' }}>
        <Button variant="outline" disabled={step === 0} onClick={() => setStep(step - 1)}>
          Back
        </Button>
        <Button variant="outline" disabled={step === steps.length - 1} onClick={() => setStep(step + 1)}>
          Next
        </Button>
        <Checkbox checked={linear} onCheckedChange={(checked) => setLinear(checked)}>
          Linear
        </Checkbox>
        <Checkbox checked={billingInvalid} onCheckedChange={(checked) => setBillingInvalid(checked)}>
          Billing invalid
        </Checkbox>
      </div>
      <p style={{ margin: 0 }}>Current step: {steps[step]}</p>
    </div>
  );
}
```

### Live demo: Stepper layouts and templates

Live demo: https://salmonui.dev/demos/navigation/stepper-vertical

Orientation and logical label placement, an explicit step status, a disabled step, and a read-only Stepper whose steps come from renderStep.

`Demo.tsx`:

```tsx
'use client';
import { useState } from 'react';
import { Select } from '@salmonui/dropdowns/select';
import { Step, Stepper, type StepperProps } from '@salmonui/navigation/stepper';

const placements = ['end', 'start', 'bottom', 'top'] as const;
const ORIENTATIONS = ['vertical', 'horizontal'];

export default function StepperVerticalDemo() {
  const [orientation, setOrientation] = useState<NonNullable<StepperProps['orientation']>>('vertical');
  const [placement, setPlacement] = useState<(typeof placements)[number]>('end');
  return (
    <div style={{ display: 'grid', gap: 16 }}>
      <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
        <label>
          Orientation{' '}
          <Select aria-label="Orientation" data={ORIENTATIONS} value={orientation} onValueChange={(value) => value != null && setOrientation(value as 'vertical' | 'horizontal')} />
        </label>
        <label>
          Label placement{' '}
          <Select aria-label="Label placement" data={placements} value={placement} onValueChange={(value) => value != null && setPlacement(value as (typeof placements)[number])} />
        </label>
      </div>
      <Stepper aria-label="Deployment" orientation={orientation} labelPlacement={placement} defaultValue={2} onStepClick={(event) => console.log('step', event.index, event.source)}>
        <Step label="Build" />
        <Step label="Test" status="completed" />
        <Step label="Deploy" />
        <Step label="Verify" disabled />
      </Stepper>
      <Stepper aria-label="Order status" readOnly value={1} renderStep={(ctx) => (
          <span style={{ display: 'grid', gap: 2 }}>
            <span>{`${ctx.index + 1}. ${String(ctx.label)}`}</span>
            <small style={{ color: 'var(--salmon-text-secondary)' }}>{ctx.status}</small>
          </span>
        )}>
        <Step label="Ordered" />
        <Step label="Packed" />
        <Step label="Delivered" />
      </Stepper>
    </div>
  );
}
```

### Live demo: Stepper events and templates

Live demo: https://salmonui.dev/demos/navigation/stepper-events

A sign-up Stepper whose onBeforeValueChange refuses to leave the first step without a workspace name, an onValueChange log, step content from renderStep and one step that overrides it with its own children.

`Demo.tsx`:

```tsx
'use client';
import { useState } from 'react';
import { Step, Stepper } from '@salmonui/navigation/stepper';
import { TextField } from '@salmonui/inputs/text-field';

const labels = ['Details', 'Plan', 'Payment', 'Done'];

export default function StepperEventsDemo() {
  const [step, setStep] = useState(0);
  const [name, setName] = useState('');
  const [log, setLog] = useState<readonly string[]>([]);
  const add = (entry: string) => setLog((list) => [entry, ...list].slice(0, 5));
  return (
    <div style={{ display: 'grid', gridTemplateColumns: 'minmax(0, 1fr)', gap: 16 }}>
      {/* Four text steps need about 340px: on a narrower screen the strip scrolls instead of squeezing. */}
      <div style={{ overflowX: 'auto', padding: 2 }}>
      <Stepper
        aria-label="Sign up"
        value={step}
        onBeforeValueChange={(event) => {
          // Leaving the first step forward needs a workspace name.
          if (event.previousValue === 0 && event.value > 0 && name.trim() === '') {
            event.preventDefault();
            add(`onBeforeValueChange cancelled ${labels[event.previousValue]} → ${labels[event.value]} (${event.source}): name is empty`);
          }
        }}
        onValueChange={(next, event) => {
          setStep(next);
          add(`onValueChange → ${labels[next]} (${event.source})`);
        }}
        renderStep={(ctx) => (
          <span style={{ display: 'grid', gap: 2 }}>
            <span>
              {ctx.index + 1}. {ctx.label}
            </span>
            <small style={{ color: 'var(--salmon-text-secondary)' }}>{ctx.status}</small>
          </span>
        )}
      >
        <Step label="Details" invalid={step > 0 && name.trim() === ''} />
        <Step label="Plan" />
        <Step label="Payment" />
        {/* Step children win over renderStep for this step only. */}
        <Step label="Done">
          <span>
            <span aria-hidden="true">✓ </span>Done
          </span>
        </Step>
      </Stepper>
      </div>
      <TextField label="Workspace name" value={name} onValueChange={(value) => setName(value)} placeholder="Required to continue" style={{ maxInlineSize: 320 }} />
      <div className="demo-log" aria-live="polite">
        {log.length === 0 ? (
          <span style={{ color: 'var(--salmon-text-secondary)' }}>No events yet.</span>
        ) : (
          <ol>
            {log.map((entry, index) => (
              <li key={`${index}-${entry}`}>{entry}</li>
            ))}
          </ol>
        )}
      </div>
    </div>
  );
}
```
