# Multi-step form

> Guided 3-step workspace intake form that preserves entered values across Back/Next transitions and builds a live review summary.

- Kind: block · Category: Auth · Interactivity: script
- Install: `npx shadcn@latest add @haze/multi-step-form`
- File: `src/components/haze/blocks/multi-step-form.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/blocks/multi-step-form

## Use when
- Breaking account or workspace creation into focused steps with a final review screen
- Preserving all form inputs in memory as users step backward and forward

## Avoid when
- Asking 1–2 fields that fit comfortably on a single short form; use auth-sign-in-card

## Alternatives
- [stepper](https://hazeui.com/ui/stepper.md)
- [ai-setup-wizard](https://hazeui.com/blocks/ai-setup-wizard.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-multi-step-form" | no | Unique prefix for form labels and heading IDs. |
| heading | `string` | "Create your workspace" | no | Form card heading. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- Every input and select across all three steps has an explicit label and preserves its value when hidden.
- Step transitions and final submission announce status in a polite role="status" element.
- Key Tab: Move across step inputs, Back and Continue/Create workspace buttons
- Key Enter / Space: Navigate between steps or submit the reviewed configuration

## Agent prompts

### Install and use

Install the Haze UI block "Multi-step form" with `npx shadcn@latest add @haze/multi-step-form`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import MultiStepForm from "@/components/haze/blocks/multi-step-form.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/multi-step-form.md

### Customize with real content

Adapt the Haze multi-step-form block for our product. Replace the demo values of these props with our real content: id, heading, class. Keep the layout, the heading level rules and these accessibility details: Every input and select across all three steps has an explicit label and preserves its value when hidden. Step transitions and final submission announce status in a polite role="status" element. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using multi-step-form, check it fits: use it when breaking account or workspace creation into focused steps with a final review screen; preserving all form inputs in memory as users step backward and forward. Avoid it when asking 1–2 fields that fit comfortably on a single short form; use auth-sign-in-card. Alternatives: @haze/stepper, @haze/ai-setup-wizard.

## Example requests that should lead here
- Build a 3-step workspace creation form with progress bars, preserved state and a live review summary step

## Source

```astro
---
import { ArrowLeft, ArrowRight, Check } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  id?: string;
  heading?: string;
  class?: string;
}

const { id = "haze-multi-step-form", heading = "Create your workspace", class: className } = Astro.props;
---

<section aria-labelledby={`${id}-title`} data-haze-ms-form class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <div class="mx-auto max-w-xl rounded-2xl border border-border bg-card p-6 sm:p-8">
    <header class="flex flex-wrap items-center justify-between gap-2 border-b border-border pb-4">
      <div>
        <h2 id={`${id}-title`} class="text-lg/7 font-semibold tracking-tight text-foreground">{heading}</h2>
        <p data-msf-sub class="text-xs/5 text-muted-foreground">Step 1 of 3 · Workspace basics</p>
      </div>
      <div class="flex items-center gap-1.5" aria-hidden="true">
        {[0, 1, 2].map((i) => <span data-msf-bar={String(i)} class={cn("h-1.5 w-8 rounded-full transition-colors duration-150", i === 0 ? "bg-primary" : "bg-muted")}></span>)}
      </div>
    </header>

    <form data-msf-form class="mt-5">
      <div data-msf-step="0" class="grid gap-4">
        <div class="grid gap-1.5">
          <label for={`${id}-ws`} class="text-xs font-medium text-foreground">Workspace name</label>
          <input id={`${id}-ws`} data-msf-field="workspace" type="text" value="Tidewell Labs" class="h-10 rounded-lg border border-frame-input bg-field px-3 text-sm text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
        </div>
        <div class="grid gap-1.5">
          <label for={`${id}-slug`} class="text-xs font-medium text-foreground">Workspace URL</label>
          <div class="flex h-10 items-center overflow-hidden rounded-lg border border-frame-input bg-field has-[input:focus-visible]:border-ring has-[input:focus-visible]:ring-3 has-[input:focus-visible]:ring-ring/24">
            <span class="border-r border-border bg-muted/50 px-3 font-mono text-xs text-muted-foreground">haze.app/</span>
            <input id={`${id}-slug`} data-msf-field="slug" type="text" value="tidewell" class="h-full min-w-0 flex-1 bg-transparent px-3 font-mono text-xs text-foreground outline-hidden" />
          </div>
        </div>
      </div>

      <div data-msf-step="1" hidden class="grid gap-4">
        <div class="grid gap-1.5">
          <label for={`${id}-size`} class="text-xs font-medium text-foreground">Team size</label>
          <select id={`${id}-size`} data-msf-field="size" class="h-10 rounded-lg border border-frame-input bg-field px-3 text-sm text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground">
            <option>1–10 people</option>
            <option selected>11–50 people</option>
            <option>51–250 people</option>
            <option>250+ people</option>
          </select>
        </div>
        <div class="grid gap-1.5">
          <label for={`${id}-region`} class="text-xs font-medium text-foreground">Data region</label>
          <select id={`${id}-region`} data-msf-field="region" class="h-10 rounded-lg border border-frame-input bg-field px-3 text-sm text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground">
            <option selected>EU-West (Frankfurt)</option>
            <option>US-East (Virginia)</option>
            <option>AP-South (Singapore)</option>
          </select>
        </div>
      </div>

      <div data-msf-step="2" hidden class="space-y-3">
        <p class="text-xs font-medium text-foreground">Review your configuration</p>
        <dl class="divide-y divide-border rounded-xl border border-border bg-muted/40 text-xs">
          <div class="flex justify-between gap-4 px-3.5 py-2.5"><dt class="text-muted-foreground">Workspace</dt><dd data-msf-sum="workspace" class="font-medium text-foreground">Tidewell Labs</dd></div>
          <div class="flex justify-between gap-4 px-3.5 py-2.5"><dt class="text-muted-foreground">URL</dt><dd data-msf-sum="slug" class="font-mono text-foreground">haze.app/tidewell</dd></div>
          <div class="flex justify-between gap-4 px-3.5 py-2.5"><dt class="text-muted-foreground">Team size</dt><dd data-msf-sum="size" class="text-foreground">11–50 people</dd></div>
          <div class="flex justify-between gap-4 px-3.5 py-2.5"><dt class="text-muted-foreground">Region</dt><dd data-msf-sum="region" class="text-foreground">EU-West (Frankfurt)</dd></div>
        </dl>
      </div>

      <div class="mt-6 flex items-center justify-between gap-2 border-t border-border pt-4">
        <button type="button" data-msf-prev disabled class="inline-flex h-9 cursor-pointer items-center gap-1.5 rounded-lg border border-frame bg-field px-3 text-xs font-medium text-foreground hover:bg-accent disabled:cursor-not-allowed disabled:opacity-45 focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
          <ArrowLeft class="size-3.5" aria-hidden="true" />
          Back
        </button>
        <button type="button" data-msf-next class="inline-flex h-9 cursor-pointer items-center gap-1.5 rounded-lg bg-primary px-4 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
          <span data-msf-next-label>Continue</span>
          <ArrowRight class="size-3.5" aria-hidden="true" />
        </button>
      </div>
    </form>

    <p data-msf-status role="status" class="mt-3 min-h-4 text-xs/4 text-muted-foreground"></p>
  </div>
</section>

<script>
  function initMsForms() {
    const subs = ["Step 1 of 3 · Workspace basics", "Step 2 of 3 · Team & region", "Step 3 of 3 · Review & create"];
    document.querySelectorAll<HTMLElement>("[data-haze-ms-form]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      root.setAttribute("data-enhanced", "");
      const steps = Array.from(root.querySelectorAll<HTMLElement>("[data-msf-step]"));
      const bars = Array.from(root.querySelectorAll<HTMLElement>("[data-msf-bar]"));
      const sub = root.querySelector<HTMLElement>("[data-msf-sub]");
      const prev = root.querySelector<HTMLButtonElement>("[data-msf-prev]");
      const next = root.querySelector<HTMLButtonElement>("[data-msf-next]");
      const nextLabel = root.querySelector<HTMLElement>("[data-msf-next-label]");
      const status = root.querySelector<HTMLElement>("[data-msf-status]");
      let cur = 0;

      const syncSummary = () => {
        const val = (k: string) => root.querySelector<HTMLInputElement | HTMLSelectElement>(`[data-msf-field="${k}"]`)?.value ?? "";
        const set = (k: string, text: string) => { const el = root.querySelector<HTMLElement>(`[data-msf-sum="${k}"]`); if (el) el.textContent = text; };
        set("workspace", val("workspace"));
        set("slug", `haze.app/${val("slug")}`);
        set("size", val("size"));
        set("region", val("region"));
      };

      const render = (msg?: string) => {
        steps.forEach((s, i) => (s.hidden = i !== cur));
        bars.forEach((b, i) => (b.className = i <= cur ? "h-1.5 w-8 rounded-full bg-primary transition-colors duration-150" : "h-1.5 w-8 rounded-full bg-muted transition-colors duration-150"));
        if (sub) sub.textContent = subs[cur];
        if (prev) prev.disabled = cur === 0;
        if (nextLabel) nextLabel.textContent = cur === 2 ? "Create workspace" : "Continue";
        if (cur === 2) syncSummary();
        if (status) status.textContent = msg ?? subs[cur];
      };

      prev?.addEventListener("click", () => { if (cur > 0) { cur--; render(); } });
      next?.addEventListener("click", () => {
        if (cur < 2) { cur++; render(); }
        else render("Workspace created (demo flow).");
      });
    });
  }
  initMsForms();
  document.addEventListener("astro:page-load", initMsForms);
</script>
```
