# Steps form

> A multi-step form in one card that changes shape: steps slide in from the way you’re going, checks shake and explain, and Create turns into what comes next.

Onboarding, checkout, setup: most multi-step forms jump between pages and lose you in between. This one is a single card. A bar of segments fills as you go, the step’s name and title morph letter by letter and "2 / 4" rolls. The next step slides in from the side you’re heading, out of a blur, while the card eases to its new height; going back slides the other way. Continue runs the step’s check, and if something’s wrong the step shakes and the reason folds open under it (an async check, like whether a name is free, shows "Checking" in the button first). Back folds out of the footer on the first step. On the last step Continue morphs into your action, spins, draws a check, and the whole card turns into whatever comes next.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/steps-form.json
```

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

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `status-button`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/steps-form
- Registry item (source): https://hairlineui.com/r/steps-form.json

## Usage

```tsx
import { StepsForm } from "@/components/steps-form";

<StepsForm
  steps={[
    { id: "name", label: "Workspace", title: "Name your workspace", content: <NameField />, validate: () => (name ? null : "Give it a name.") },
    { id: "plan", label: "Plan", title: "Pick a plan", content: <Plans /> },
  ]}
  onSubmit={() => createWorkspace({ name, plan })}
  submitLabels={{ idle: "Create workspace", pending: "Creating", success: "Created" }}
  done={<Ready />}
/>
```

## Checks against your API

A step’s validate can be async: return a message to stay, nothing to move on. onSubmit throwing an Error keeps the person on the last step with its message.

```tsx
"use client";
import { useState } from "react";
import { StepsForm } from "@/components/steps-form";

export function CreateWorkspace() {
  const [name, setName] = useState("");
  return (
    <StepsForm
      steps={[
        {
          id: "name",
          label: "Workspace",
          title: "Name your workspace",
          content: <input value={name} onChange={(e) => setName(e.target.value)} aria-label="Workspace name" />,
          validate: async () => {
            if (name.trim().length < 2) return "Give it a name, two letters or more.";
            const res = await fetch(`/api/workspaces/available?name=${encodeURIComponent(name)}`);
            if (!(await res.json()).available) return "That name is taken. Try another.";
          },
        },
        // …more steps
      ]}
      onSubmit={async () => {
        const res = await fetch("/api/workspaces", { method: "POST", body: JSON.stringify({ name }) });
        if (!res.ok) throw new Error("We couldn’t create it just now. Try again.");
      }}
      submitLabels={{ idle: "Create workspace", pending: "Creating", success: "Created" }}
      done={<p>{name} is ready.</p>}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `steps` | `{ id, label, title, description?, content, validate? }[]` | – | In order. You own the fields’ state; content is whatever the step shows. |
| `onSubmit` | `() => void \| Promise<void>` | – | Runs after the last step’s check. Throw to stay on the last step; the error’s message is shown. |
| `submitLabels` | `{ idle?, pending?, success? }` | `"Create", "Creating", "Created"` | The last button’s labels as it runs. |
| `done` | `ReactNode` | – | What the card turns into once it’s submitted. |
| `onStepChange` | `(index: number) => void` | – | Runs when the step changes, e.g. for analytics. |

## States

- **header**: Segments fill left to right as scaleX (520ms); the label and title morph; the counter rolls.
- **step**: The new step slides 28px in from the direction you’re going out of a 4px blur (420ms) while the old one slides out the other way (260ms); the card’s height eases (440ms). Focus moves to the new step’s first field.
- **check**: validate returns a message: the step shakes (±6px, 380ms) and the message folds open under it with an alert icon. A promise shows the button’s spinner and "Checking" until it settles.
- **back**: Hidden on the first step by folding its column to nothing (360ms), so Continue never jumps.
- **submit**: On the last step the button reads your label; onSubmit runs with Status button’s spinner, then a drawn check, and 750ms later the header and footer fold away and done replaces the step. A thrown error shows its message and "Try again".

## What it handles

Onboarding, checkout and setup flows usually jump between pages and lose people in between. This keeps the whole flow in one card that changes shape, and checks each step before moving on.

- **One card, many steps**: The next step slides in from the way you’re heading while the card eases to its new height. Going back slides the other way.
- **Progress people can see**: A bar of segments fills, the step’s title morphs and “2 / 4” rolls.
- **Checks before moving on**: validate() can be async. A problem shakes the step and the reason folds open under it.
- **Back only when there is a back**: The Back button folds away on the first step, so Continue never jumps.
- **Submit shows its work**: On the last step Continue becomes your action, spins, draws a check, and the card turns into whatever comes next.
- **Keyboard and focus**: Enter continues, focus moves to the new step’s first field, and errors are announced.

## Replaces

a wizard, step transitions, a progress bar, per-step validation, an async submit state, a completion screen

## Where it fits

- **Onboarding and account setup**: Collect the few things a new account needs, one step at a time.
- **Checkout and booking**: Details, delivery and payment in one place.
- **Create-project wizards**: Name it, configure it and create it without leaving the card.
- **Applications and surveys**: Longer forms broken into short steps.

## Notes

- It’s a form: Enter in a field continues, the title labels it, and errors are announced with role="alert".
- Focus moves to each new step’s first field (or an element marked data-autofocus), but not on first load.
- Steps that aren’t showing are unmounted, so keep their values in your own state, as the demo does.
- Installs Number roll, Status button and Text morph. With reduced motion steps swap in place, nothing shakes, and the card resizes instantly.

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