# Wizard (/navigation/wizard)





<ComponentPreview name="wizard-preskok-demo" previewClassName="max-h-none" description="Listing flow with a validated vehicle step, photo upload, pricing and a review step with edit links." />

A wizard moves people forward one step at a time and lets them go back to earlier steps. Going back
makes the current step the furthest one again, unless you track progress with `completedKeys`. To
only show progress without navigation, use a [Progress List](/feedback/progress-list).

## Gated steps [#gated-steps]

<ComponentPreview name="wizard-vertical-preskok-demo" previewClassName="max-h-none" description="Vertical dealer onboarding that unlocks each step once the previous one is valid." />

Pass `completedKeys` to decide when a step is done, for example once its fields are valid. People
can reach every enabled step up to and including the first enabled step after the last completed one, including earlier
steps that are not completed yet. The next button stops there, so compute `completedKeys` in order,
as the example does. Without `completedKeys`, every step before the current one counts as completed. Set
`allowsSelectingIncompleteSteps` to make every enabled step reachable at any time. In that mode no
step counts as completed unless you pass `completedKeys`.

## Installation [#installation]

<CodeTabs>
  <TabsList>
    <TabsTrigger id="cli">
      CLI
    </TabsTrigger>

    <TabsTrigger id="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent id="cli">
    ```bash
    npx shadcn@latest add @preskok/wizard
    ```
  </TabsContent>

  <TabsContent id="manual">
    <Steps>
      <Step>
        Copy and paste the following code into your project.

        <ComponentSource name="wizard" title="registry/preskok/ui/preskok-ui/wizard.tsx" />
      </Step>

      <Step>
        Update the import paths to match your project setup.
      </Step>
    </Steps>
  </TabsContent>
</CodeTabs>

## Usage [#usage]

```tsx
import { Button } from "@/components/ui/preskok-ui/button"
import {
  Wizard,
  WizardButtons,
  WizardPanel,
  WizardPanels,
  WizardStep,
  WizardStepList,
} from "@/components/ui/preskok-ui/wizard"

const steps = [
  { id: "account", label: "Account", content: <AccountForm /> },
  { id: "billing", label: "Billing", content: <BillingForm /> },
  { id: "review", label: "Review", content: <Summary /> },
]

export function Signup({ onCreate }: { onCreate: () => void }) {
  return (
    <Wizard>
      <WizardStepList aria-label="Sign up" items={steps}>
        {(step) => <WizardStep>{step.label}</WizardStep>}
      </WizardStepList>
      <WizardPanels items={steps}>
        {(step) => <WizardPanel>{step.content}</WizardPanel>}
      </WizardPanels>
      <WizardButtons
        finish={<Button onPress={onCreate}>Create account</Button>}
      />
    </Wizard>
  )
}
```

`WizardButtons` renders buttons in the `previous` and `next` slots. They move between steps and are
disabled when there is no step to move to. On the last step, `finish` replaces the next button.
Trailing steps disabled with `isDisabled` or the Wizard's `disabledKeys` are skipped when finding
the last step. Panels unmount when their
step is not selected, so keep form values in state above the `Wizard`. You
can also place your own `<Button slot="previous">` and `<Button slot="next">` anywhere inside the
`Wizard`. When Next turns into the finish action on the last step, focus moves to the current step
in the step list.

Each step id must match a `WizardPanel` id. Steps support `isDisabled` and `description`, and
`orientation="vertical"` puts the step list beside the panels. `WizardStateContext` exposes the
current, previous and next keys to custom controls.
