GooseUI

Components

Step Wizard

New

A frame for questionnaires and sign-up flows that show one question at a time. Every step is a <details> with a shared name, so the browser keeps exactly one step open. The summary of the open step is its title, and the summaries of its neighbours become the Back and Next buttons. While a step has an invalid field, :has(:invalid) swaps Next for a disabled button. Progress, the counter and the transitions are CSS. The base component is a Server Component with no JavaScript; the optional client version from step-wizard-client adds async validate, onComplete, onStepChange and the useStepWizard hook.

Browser Support

Mutually exclusive <details> elements

Groups expandable sections

Your browser:
:has()

Styles elements based on their contents

Your browser:
color-mix()

Colors focus rings and step buttons

Your browser:

Preview

This wizard is a Server Component inside a form, with no JavaScript. Next stays locked until the step is valid.

What are you planning?

Step 1 of 4
NextBack

Next stays locked until you pick an option.

How many people?

Step 2 of 4
NextBack

How should we call you?

Step 3 of 4
NextBack

At least two letters: the minlength attribute checks it.

All set

Step 4 of 4
NextBack

Finish submits the form. Here it is a dialog form, so nothing is sent.

Installation

npx shadcn@latest add @gooseui/step-wizard
pnpm dlx shadcn@latest add @gooseui/step-wizard
yarn dlx shadcn@latest add @gooseui/step-wizard
bunx --bun shadcn@latest add @gooseui/step-wizard

Usage

import { Textarea } from "@/components/ui/textarea"
import { Input } from "@/components/ui/input"

import { StepWizard, StepWizardStep } from "@/components/ui/step-wizard"

// Server Component, no JavaScript: Finish submits the form
export default function Survey() {
  return (
    <form action={saveSurvey}>
      <StepWizard transition="slide">
        <StepWizardStep title="How should we call you?">
          <Input name="name" required minLength={2} />
        </StepWizardStep>
        <StepWizardStep title="Anything else?" description="Optional">
          <Textarea name="note" />
        </StepWizardStep>
      </StepWizard>
    </form>
  )
}

Examples

Client version

StepWizard and StepWizardStep from step-wizard-client render the same markup and add validate, onComplete and onStepChange. Switch transitions above the card and try pressing Next on the first step without picking anything.

Transition

What are you planning?

Step 1 of 4
NextBack

Pick the closest option, you can change it later.

How many people?

Step 2 of 4
NextBack

How should we call you?

Step 3 of 4
NextBack

The name is checked on the server, it takes a moment.

All set

Step 4 of 4
NextBack

Press Finish to send your answers.

import { Textarea } from "@/components/ui/textarea"
import { Input } from "@/components/ui/input"

"use client"

import { StepWizard, StepWizardStep } from "@/components/ui/step-wizard-client"

export default function Survey() {
  const [name, setName] = useState("")

  return (
    <StepWizard transition="slide" onComplete={() => console.log("done")}>
      <StepWizardStep
        title="How should we call you?"
        validate={() => (name.trim() ? true : "Type your name")}
      >
        <Input value={name} onChange={(e) => setName(e.target.value)} />
      </StepWizardStep>
      <StepWizardStep title="Anything else?" description="Optional">
        <Textarea />
      </StepWizardStep>
    </StepWizard>
  )
}

Custom controls

Turn off the built-in buttons with showControls={false} and drive the wizard with useStepWizard(). Here a click on an option moves forward at once.

Pick a color

Step 1 of 3
NextBack

Pick a size

Step 2 of 3
NextBack

You picked

Step 3 of 3
NextBack

You picked: ,

import { Button } from "@/components/ui/button"

import { useStepWizard } from "@/components/ui/step-wizard-client"

function Choices({ options, onPick }) {
  const { next, back, isFirst } = useStepWizard()
  return (
    <>
      {options.map((option) => (
        <Button key={option} onClick={() => { onPick(option); next() }}>
          {option}
        </Button>
      ))}
      {!isFirst && <Button onClick={back}>Back</Button>}
    </>
  )
}

<StepWizard showControls={false}>
  <StepWizardStep title="Pick a color">
    <Choices options={["Sand", "Moss", "Slate"]} onPick={setColor} />
  </StepWizardStep>
  <StepWizardStep title="Pick a size">
    <Choices options={["S", "M", "L", "XL"]} onPick={setSize} />
  </StepWizardStep>
</StepWizard>

Async validation

validate may return a promise. While it runs the Next button is locked. Return a string to block the step and show it as an error.

Your email

Step 1 of 2
NextBack

Try taken@example.com to see an async error.

Choose a password

Step 2 of 2
NextBack

At least 8 characters.

<StepWizardStep
  title="Your email"
  validate={async () => {
    const res = await fetch(`/api/email-free?email=${email}`)
    const { free } = await res.json()
    return free ? true : "This email is already registered"
  }}
>
  <Input type="email" value={email} onChange={(e) => setEmail(e.target.value)} />
</StepWizardStep>

Transitions

fade-rise, slide, scale-blur, wipe and stagger. The open step plays a CSS animation; the closing one disappears at once. With reduced motion every transition becomes a short fade.

<StepWizard transition="wipe">…</StepWizard>
<StepWizard transition="stagger">…</StepWizard>

Props

PropTypeDefaultDescription
childrenReactNode-StepWizardStep elements, one per step
transition"fade-rise" | "slide" | "scale-blur" | "wipe" | "stagger""fade-rise"Animation between steps
defaultStepnumber0Zero-based step shown on mount
onStepChange(step: number) => void-Client version only: called with the new step index
onComplete() => void | Promise<void>-Client version only: called after the last step passes validation, may be async. A thrown error or rejected promise is shown as the step error. Without it Finish submits the surrounding form
showProgressbooleantrueShow the progress bar and the 01 / 04 counter
showControlsbooleantrueRender the built-in Back, Next and Finish buttons
labelsPartial<StepWizardLabels>-Texts of the buttons, the progress label and the fallback error
namestringuseId()Shared name of the step <details>. Generated when omitted
errorstring | null-Error under the step, for example from a server action
pendingbooleanfalseBusy state: a spinner replaces the Next arrow
classNamestring-Additional CSS classes

Components

StepWizardStep

PropTypeDefaultDescription
titleReactNode-Step heading. It is the summary of the step, so focus stays on it after Next
descriptionReactNode-Text under the heading
validate() => boolean | string | undefined | Promise<…>-Client version only: check before moving on, false or a string blocks the step
headingAs"h2" | "h3" | "h4""h2"Heading element of the title
classNamestring-Additional CSS classes

useStepWizard

Comes from step-wizard-client. Returns the wizard state and actions and works in any component inside the client StepWizard.

ValueTypeDescription
stepnumberZero-based index of the current step
totalnumberNumber of steps
isFirstbooleanThe current step is the first one
isLastbooleanThe current step is the last one
progressnumberProgress from 0 to 100
pendingbooleanValidation or onComplete is running
errorstring | nullMessage returned by validate
next() => Promise<void>Validate the step and move forward, or complete on the last step
back() => voidGo one step back
goTo(step: number) => voidJump to a step without validation
setError(error: string | null) => voidShow or clear an error message