# Steps (/docs/steps)





`Steps` walks a user through a flow in order: a registration, an exam sign-up, a staff wizard. Each step has an indicator (its number, a check once complete, or your icon), a title and an optional description, and the connectors between steps fill as the flow advances. Each step shows its own content panel, and a completed panel takes over once the last step is done.

```tsx
import { Steps } from '@42-central/ui-react/steps';

<Steps
  withControls
  data={[
    { title: 'Account', description: 'Email and password', content: <Account /> },
    { title: 'Campus', description: "Where you'll study", content: <Campus /> },
    { title: 'Confirm', content: <Confirm /> },
  ]}
  completed={<Welcome />}
/>
```

<Callout>
  Steps doesn't validate anything. Your app decides when the user may move on: control `step` and only advance it once the step's form is valid, or pass Ark's `isStepValid` so Next refuses to move. See [Gating Next](#gating-next).
</Callout>

## Playground [#playground]

<story.Playground />

## Steps [#steps]

`data` is an array of `{ title, description?, content?, icon?, error?, disabled?, testId? }`. The step is an index: `0` is the first step, and `data.length` is the completed state, which shows the `completed` panel.

Set `withControls` to render Back/Next buttons under the panels. On the last step Next reads "Finish" and completes the flow; once complete, only Back remains. Leave `withControls` off when your own buttons drive the step.

<story.Preview variant="Default" />

Each step's trigger gets ``data-testid={`step-${index}`}`` (or the item's own `testId`), its panel `` `${testId}-panel` ``. The Back and Next buttons and the completed panel take `steps-prev`, `steps-next` and `steps-completed`, prefixed by the root's `testId` when you set one. See the [Testing](/docs/testing) guide.

## States [#states]

A step is **upcoming**, **current** or **complete**, from its position against the current step. Mark one `error: true` to show a cross in red instead, whatever its position: Ark has no error state of its own, so your app decides when a step has one (a failed server check, a missing document).

<story.Preview variant="Error" />

<story.Preview variant="Completed" />

## Icons [#icons]

Give a step an `icon` to show instead of its number. The check replaces it once the step is complete, and the cross on error. Swap those two for the whole stepper with `icons={{ complete, error }}`.

<Preview code="&#x22;<StepsIconsExample />&#x22;">
  <StepsIconsExample />
</Preview>

## Navigation [#navigation]

By default any step can be clicked. With `linear`, only the completed steps (and the current one) can: the steps ahead wait for Next. A completed step stays clickable, so the user can always go back and change an answer. This differs from Ark's own `linear`, which locks every step. A step with `disabled: true` can never be clicked.

<story.Preview variant="Linear" />

## Gating Next [#gating-next]

Control `step` with `onChange` and render your own buttons, then only let the user move on once the step is done. Here Next stays disabled until the rules are accepted:

<Preview code="&#x22;<StepsGatedExample />&#x22;">
  <StepsGatedExample />
</Preview>

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

<Steps step={step} onChange={setStep} linear data={steps} />
<Button disabled={!isValid(step)} onClick={() => setStep(step + 1)}>Next</Button>
```

To keep the built-in buttons instead, pass `isStepValid={(index) => …}`. Next then refuses to leave an invalid step, and `onStepInvalid` tells you it tried.

## Orientation [#orientation]

`orientation="vertical"` runs the list down the side, with the panels and buttons beside it. The connectors run under the indicators, past descriptions of any length.

<story.Preview variant="Vertical" />

### Narrow containers [#narrow-containers]

A horizontal list narrower than 30rem keeps only the current step's title and description on screen, so the indicators and connectors still fit a phone. The other titles stay in each step's accessible name. The list measures itself, not the viewport, so the same stepper collapses in a narrow sidebar on a wide screen.

<Preview code="&#x22;<StepsCompactExample />&#x22;">
  <StepsCompactExample />
</Preview>

## Sizes [#sizes]

Five sizes, `xs` through `xl`, scaling the indicator, the text and the gaps together. The built-in buttons follow the stepper's size.

<Preview code="&#x22;<StepsSizesExample />&#x22;">
  <StepsSizesExample />
</Preview>

## Colors [#colors]

Without a `color`, the stepper uses the default palette. With one, the current step's wash, the completed fills and the connectors' progress take it. `color` lands on `Steps.List` only, so a `Button` inside a panel keeps its own palette. The built-in Next button takes it too.

<Preview code="&#x22;<StepsColorsExample />&#x22;">
  <StepsColorsExample />
</Preview>

## Compound API [#compound-api]

Drop to the parts for anything the `data` array can't express: custom trigger content, panels elsewhere on the page, your own footer. `size`, `color`, `linear`, `translations` and `icons` live on `Steps.Root`, which needs a `count`.

<Preview code="&#x22;<StepsCompoundExample />&#x22;">
  <StepsCompoundExample />
</Preview>

```tsx
'use client';
import { Steps } from '@42-central/ui-react/steps';

<Steps.Root count={3} color="green">
  <Steps.List>
    {titles.map((title, index) => (
      <Steps.Item key={title} index={index}>
        <Steps.Trigger>
          <Steps.Indicator />
          <Steps.Title>{title}</Steps.Title>
          <Steps.Description>Optional</Steps.Description>
        </Steps.Trigger>
        <Steps.Separator />
      </Steps.Item>
    ))}
  </Steps.List>
  {titles.map((title, index) => (
    <Steps.Content key={title} index={index}>…</Steps.Content>
  ))}
  <Steps.CompletedContent>Submitted.</Steps.CompletedContent>
  <Steps.PrevTrigger />
  <Steps.NextTrigger />
</Steps.Root>
```

`Steps.Root` lays its children out in a column when horizontal and in a row when vertical; wrap the panels in your own element in a vertical stepper so they stack beside the list.

## Anatomy [#anatomy]

* **`Steps.Root`** — the Ark machine (`count`, `step` / `defaultStep`, `onStepChange`, `isStepValid`), the kit's `size` / `color` / `linear` / `translations` / `icons`, and the screen-reader announcer.
* **`Steps.List`** — the row (or column) of steps; carries the `color`.
* **`Steps.Item`** — one step, with its `index`, and `error` / `disabled`.
* **`Steps.Trigger`** — the step's button, around its indicator and text.
* **`Steps.Indicator`** — the round marker: number, check, cross, or its `children` as a custom icon.
* **`Steps.Title`*&#x2A; / &#x2A;*`Steps.Description`** — the step's text.
* **`Steps.Separator`** — the connector to the next step; renders nothing on the last.
* **`Steps.Content`*&#x2A; / &#x2A;*`Steps.CompletedContent`** — a step's panel, and the one shown once complete.
* **`Steps.PrevTrigger`*&#x2A; / &#x2A;*`Steps.NextTrigger`** — kit `Button`s that move back and forward.
* **`Steps.Context`** — a render prop with Ark's API (`value`, `count`, `setStep`, `goToNextStep`…).

Every part takes its own `testId` prop, rendered as `data-testid` on that part.

## API [#api]

<TypeTable
  type="{
  data: {
    type: '{ title, description?, content?, icon?, error?, disabled?, testId? }[]',
    description: 'The steps, in order. Data form only; the compound Steps.Root takes a count instead.',
  },
  completed: {
    type: 'ReactNode',
    description: 'The panel shown once every step is complete. Data form only.',
  },
  withControls: {
    type: 'boolean',
    default: 'false',
    description: 'Render Back/Next buttons under the panels. Data form only.',
  },
  step: {
    type: 'number',
    description: 'Controlled step index. data.length (or count) is the completed state.',
  },
  defaultStep: {
    type: 'number',
    default: '0',
    description: 'Uncontrolled initial step.',
  },
  onChange: {
    type: '(step: number) => void',
    description: 'Fires with the new step index. Data form; Steps.Root takes Ark\'s onStepChange({ step }).',
  },
  onStepComplete: {
    type: '() => void',
    description: 'Fires when the flow reaches the completed state.',
  },
  isStepValid: {
    type: '(index: number) => boolean',
    description: 'Ark: Next (and clicking ahead) refuses to leave a step that returns false.',
  },
  onStepInvalid: {
    type: '(details: { step, action, targetStep? }) => void',
    description: 'Ark: fires when isStepValid refused a move.',
  },
  linear: {
    type: 'boolean',
    default: 'false',
    description: 'Only completed steps and the current one can be clicked. Completed steps stay clickable, unlike Ark\'s own linear.',
  },
  orientation: {
    type: '&#x22;horizontal&#x22; | &#x22;vertical&#x22;',
    default: '&#x22;horizontal&#x22;',
    description: 'A row of steps over the panels, or a column beside them.',
  },
  size: {
    type: '&#x22;xs&#x22; | &#x22;sm&#x22; | &#x22;md&#x22; | &#x22;lg&#x22; | &#x22;xl&#x22;',
    default: '&#x22;md&#x22;',
    description: 'Indicator, text, gaps, and the built-in buttons.',
  },
  color: {
    type: 'Color',
    description: 'Current, completed and connector accent. Lands on Steps.List, so panels keep their own palette.',
  },
  icons: {
    type: '{ complete?: ReactNode; error?: ReactNode }',
    description: 'The check and the cross in every indicator.',
  },
  translations: {
    type: 'StepsTranslations',
    description: 'The built-in strings, merged per key over STEPS_DEFAULT_TRANSLATIONS. See below.',
  },
  testId: {
    type: 'string',
    description: 'data-testid on the root, and the prefix of the data form\'s prev / next / completed ids.',
  },
}"
/>

`Steps.Item` props (beyond Ark's `Steps.Item`):

<TypeTable
  type="{
  index: { type: 'number', required: true, description: 'The step\'s position, from 0.' },
  error: { type: 'boolean', default: 'false', description: 'Draw the step in the error state.' },
  disabled: { type: 'boolean', default: 'false', description: 'The step can never be clicked.' },
}"
/>

`Steps.PrevTrigger` and `Steps.NextTrigger` take every [`Button`](/docs/button) prop. Prev defaults to `variant="outline"`, both to the stepper's `size`, and their label to the translation when they have no `children`.

### Translations [#translations]

<TypeTable
  type="{
  prev: { type: 'string', default: '&#x22;Back&#x22;', description: 'PrevTrigger\'s label.' },
  next: { type: 'string', default: '&#x22;Next&#x22;', description: 'NextTrigger\'s label.' },
  finish: { type: 'string', default: '&#x22;Finish&#x22;', description: 'NextTrigger\'s label on the last step.' },
  complete: { type: 'string', default: '&#x22;Completed&#x22;', description: 'Added to a completed step\'s accessible name.' },
  error: { type: 'string', default: '&#x22;Has errors&#x22;', description: 'Added to an errored step\'s accessible name.' },
  progress: { type: '(step: number, count: number) => string', default: '`Step ${step} of ${count}`', description: 'Announced when the step changes; step counts from 1.' },
  done: { type: 'string', default: '&#x22;All steps completed&#x22;', description: 'Announced when the flow completes.' },
}"
/>

## Accessibility [#accessibility]

* Built on Ark UI's Steps machine: the list is a `tablist`, each step's trigger a `tab` with `aria-selected` and `aria-controls`, each panel a `tabpanel`, and the current step's item carries `aria-current="step"`.
* The indicator is decorative. A completed or errored step adds "Completed" or "Has errors" to its trigger's name, so the state doesn't rest on the check, the cross or the colour.
* A polite live region announces "Step 2 of 4" when the step changes, and "All steps completed" at the end: the panel swaps under a Next button that keeps focus, and nothing else would tell a screen-reader user it moved. It stays silent on the first render.
* A step that can't be clicked (`disabled`, or ahead under `linear`) is a disabled button, out of the tab order.
* Under RTL (from the locale, see [Internationalization](/docs/intl)) the steps run right to left and the connectors fill from the right. The numbers use the locale's digits.
* The connectors fill over `--duration-normal`; under `prefers-reduced-motion: reduce` they switch at once.
