Stepper

Where someone is in an ordered flow. ds::stepper is the list; ds::step is each item. Presentation only: the host decides which step is current.

Anatomy

 (✓) Account ────── (2) Plan ─────── (3) Billing ────── (4) Review
     [email protected]    Pick what you need
  ↑     ↑                                 ↑
marker  title + description            connector (solid behind a completed step)
PartTokenWhy
Marker, completesurface-inverse + on-inverse, check iconThe primary button's pair: done is the heaviest thing in the row.
Marker, current2px fg ring on surface, numberStands out by outline, not by a hue, so it holds in both themes.
Marker, upcoming1px border-strong, number in fg-muted
Marker, errordanger + on-danger, "!"
Titletext-body; semibold when current, fg-muted when upcoming
Descriptiontext-meta, fg-muted
Connectorfg after a completed step, border-strong otherwiseThe line already travelled is drawn solid.

Markers are 28px (size-7). Literal classes throughout.

Numbering

A CSS counter: the list resets ds-step, every item increments it, and the number is the marker's ::before content. A step never needs to be told its position, which Blade could not give it anyway: the children render before the parent's template runs. The number is decorative (the marker is aria-hidden); the ol gives a screen reader the position.

Orientation

horizontal (default): items in a row, each a marker with its text beside it and a connector filling the rest of its share. vertical: a column, the connector running down from each marker to the next, absolutely positioned so a long description stretches it rather than the other way round.

The stepper passes orientation to its steps with @aware.

Narrow widths

A horizontal stepper narrower than 40rem (sm, measured on the stepper: the root is @container, the variants @min-[40rem]:) keeps its markers and connectors and:

  • takes each title and description off the screen with sr-only, NOT hidden, so the list still reads in full;
  • prints, aria-hidden, "Step 2 of 4" and the current title under the row.

The count and position come from the rendered slot. By the time the stepper's template runs its steps are finished HTML, so it reads back the data-ds-step and data-ds-step-title attributes each step writes on its list item. Only steps write them. With no current step the first error is treated as current; with neither, the line counts the complete ones ("All 4 steps complete").

A container query rather than the viewport's sm: because a stepper lives inside things: a 4-step flow in a narrow modal on a desktop has to collapse, and one in a wide panel on a tablet does not. Container queries are supported everywhere the rest of this system's CSS runs; without them the @min- rules never apply and the stepper stays collapsed, which is the safe failure.

A container cannot take its width from its content, so the root is w-full.

A step with href renders its marker and text inside one anchor. Without href the same element is an anchor with no href, which is a plain inline element: no role, no tab stop. One element either way keeps the markup free of an @if inside an opening tag (the Livewire marker trap), and below 40rem the link is still the visible marker, so its focus ring shows. href on the current step is ignored: a link to where the reader already is costs a tab stop and goes nowhere, the breadcrumb's rule.

Accessibility

Rolelist (an ol) with listitems; the ol is named by label
Currentaria-current="step" on the current item
Statusin words, sr-only, after each title: "completed", "current step", "not started", "needs attention"
Keyboardnone of its own. Linked steps are links (Tab, Enter); the rest are not focusable.
Focuslinks show focus-visible with the focus-ring token, offset 2px

"Current step" is spoken as well as aria-current, because not every screen reader announces aria-current on a list item that is not focused.

Do not

  • Do not hold state in it. It renders what it is told; the flow decides.
  • Do not use it for unordered navigation. That is tabs or a nav.
  • Do not hide titles with hidden. The collapse is visual only.
  • Do not let an upcoming step link somewhere it cannot be used yet.

From the package repo: edit this page on GitHub.

Was this page helpful?