alpha

Wizard

A Wizard guides users through a multi-step process one step at a time, and allows them to navigate between the steps they have reached.

Theme 
allowsSelectingIncompleteSteps 
Example
Wizard.tsx
Wizard.css
ProjectFields.tsx
import type {Key} from 'react-aria-components/Wizard';
import {Wizard, WizardStepList, WizardStep, WizardPanels, WizardPanel} from './Wizard';
import {Button} from './Button';
import {Form} from './Form';
import {NameField, EmailField, Summary} from './ProjectFields';
import {useState} from 'react';

function Example(props) {
  let [step, setStep] = useState<Key>('details');
  let [name, setName] = useState('');
  let [email, setEmail] = useState('');
  // Next focuses the new step's content. Back restores focus to the Back button if enabled.
  let [focusTarget, setFocusTarget] = useState<'content' | 'back' | null>(null);

  function advanceToStep(key: Key) {
    setStep(key);
    setFocusTarget('content');
  }

  return (
    <Wizard
      selectedKey={step}
      onSelectionChange={key => {
        setStep(key);
        setFocusTarget(null);
      }} {...props}>
      <WizardStepList aria-label="Create project">
        <WizardStep id="details">Details</WizardStep>
        <WizardStep id="members">Members</WizardStep>
        <WizardStep id="review">Review</WizardStep>
      </WizardStepList>
      <WizardPanels>
        <WizardPanel id="details">
          <Form action={formData => {
            setName(formData.get('name') as string);
            advanceToStep('members');
          }}>
            <NameField defaultValue={name} />
            <div className="wizard-buttons">
              <Button slot="previous" type="button" variant="secondary">Back</Button>
              <Button type="submit">Next</Button>
            </div>
          </Form>
        </WizardPanel>
        <WizardPanel id="members">
          <Form action={formData => {
            setEmail(formData.get('email') as string);
            advanceToStep('review');
          }}>
            <EmailField defaultValue={email} autoFocus={focusTarget === 'content'} />
            <div className="wizard-buttons">
              <Button slot="previous" type="button" variant="secondary" autoFocus={focusTarget === 'back'}>Back</Button>
              <Button type="submit">Next</Button>
            </div>
          </Form>
        </WizardPanel>
        <WizardPanel id="review">
          <Form action={() => alert(`Created ${name}!\nEmail: ${email}`)}>
            <Summary name={name} email={email} />
            <div className="wizard-buttons">
              <Button slot="previous" type="button" variant="secondary" onPress={() => setFocusTarget('back')}>Back</Button>
              <Button type="submit" autoFocus={focusTarget === 'content'}>Create project</Button>
            </div>
          </Form>
        </WizardPanel>
      </WizardPanels>
    </Wizard>
  );
}

Content

WizardStepList and WizardPanels follow the Collection Components API, accepting both static and dynamic collections. This example shows a dynamic collection, passing a list of objects to the items prop, and a function to render the children.

Choose a username and password.
import {Wizard, WizardStepList, WizardStep, WizardPanels, WizardPanel, WizardButtons} from './Wizard';

let steps = [
  {id: 'account', label: 'Account', content: 'Choose a username and password.'},
  {id: 'profile', label: 'Profile', content: 'Add a photo and a short bio.'},
  {id: 'settings', label: 'Settings', content: 'Choose which notifications you receive.'},
  {id: 'confirm', label: 'Confirm', content: 'Check your details, then create your account.'}
];

<Wizard>
  <WizardStepList
    aria-label="Sign up"
    items={steps}>
    {step => <WizardStep>{step.label}</WizardStep>}
  </WizardStepList>
  <WizardPanels
    items={steps}>
    {step => <WizardPanel>{step.content}</WizardPanel>}
  </WizardPanels>
  <WizardButtons />
</Wizard>

Buttons with slot="previous" and slot="next" move to the previous and next steps, skipping disabled steps. They can be placed anywhere inside the Wizard, and are disabled when there is no previous or next step.

Current step

Use the defaultSelectedKey or selectedKey prop to set the current step. The selected key corresponds to the id prop of a <WizardStep>. By default, steps before the current step are marked as completed, and steps after it are disabled. Use the data-current and data-completed attributes to style them.

Invite people to work on the project with you.

Current step: members

import type {Key} from 'react-aria-components/Wizard';
import {Wizard, WizardStepList, WizardStep, WizardPanels, WizardPanel, WizardButtons} from './Wizard';
import {useState} from 'react';

function Example() {
  let [step, setStep] = useState<Key>('members');

  return (
    <div style={{maxWidth: '100%'}}>
      <Wizard
        selectedKey={step}
        onSelectionChange={setStep}
      >
        <WizardStepList aria-label="Create project">
          <WizardStep id="details">Details</WizardStep>
          <WizardStep id="members">Members</WizardStep>
          <WizardStep id="review">Review</WizardStep>
        </WizardStepList>
        <WizardPanels>
          <WizardPanel id="details">Name your project and choose who can see it.</WizardPanel>
          <WizardPanel id="members">Invite people to work on the project with you.</WizardPanel>
          <WizardPanel id="review">Check the details, then create the project.</WizardPanel>
        </WizardPanels>
        <WizardButtons />
      </Wizard>
      <p>Current step: {step}</p>
    </div>
  );
}

Completed steps

Wizards can be sequential or non-sequential. Sequential wizards must be completed in order and steps after the last completed step are disabled. Non-sequential wizards allow users to navigate to any step.

Sequential

Set completedKeys to decide which steps are completed, for example once a step's fields are valid, or to restore saved progress.

Example
ProjectFields.tsx
import type {Key} from 'react-aria-components/Wizard';
import {Wizard, WizardStepList, WizardStep, WizardPanels, WizardPanel} from './Wizard';
import {Button} from './Button';
import {NameField, EmailField, Summary} from './ProjectFields';
import {isValidName, isValidEmail} from './projectValidation';
import {useState} from 'react';

function Example() {
  let [step, setStep] = useState<Key>('details');
  let [name, setName] = useState('');
  let [email, setEmail] = useState('');
  // Only focus the field when Next changes the step.
  let [focusField, setFocusField] = useState(false);

  // A step is completed once its field is valid, and the steps before it are completed.
  let completedKeys: Key[] = [];
  if (isValidName(name)) {
    completedKeys.push('details');
    if (isValidEmail(email)) {
      completedKeys.push('members');
    }
  }

  return (
    <Wizard
      selectedKey={step}
      onSelectionChange={key => {
        setStep(key);
        setFocusField(false);
      }}
      completedKeys={completedKeys}
    >
      <WizardStepList aria-label="Create project">
        <WizardStep id="details">Details</WizardStep>
        <WizardStep id="members">Members</WizardStep>
        <WizardStep id="review">Review</WizardStep>
      </WizardStepList>
      <WizardPanels>
        <WizardPanel id="details">
          <NameField value={name} onChange={setName} autoFocus={focusField} />
        </WizardPanel>
        <WizardPanel id="members">
          <EmailField value={email} onChange={setEmail} autoFocus={focusField} />
        </WizardPanel>
        <WizardPanel id="review">
          <Summary name={name} email={email} />
        </WizardPanel>
      </WizardPanels>
      <div className="wizard-buttons">
        <Button slot="previous" variant="secondary">Back</Button>
        {step === 'review'
          ? <Button onPress={() => alert(`Created ${name}!\nEmail: ${email}`)}>Create project</Button>
          : <Button slot="next" onPress={() => setFocusField(true)}>Next</Button>}
      </div>
    </Wizard>
  );
}

Non-sequential

Set allowsSelectingIncompleteSteps to let users select any step, in any order. Steps are only completed when they are in completedKeys, so users can see which steps still need their attention. Users can reach the last step at any time, so check that every step is completed before submitting.

Example
ProjectFields.tsx
import type {Key} from 'react-aria-components/Wizard';
import {Wizard, WizardStepList, WizardStep, WizardPanels, WizardPanel} from './Wizard';
import {Button} from './Button';
import {NameField, EmailField, Summary} from './ProjectFields';
import {isValidName, isValidEmail} from './projectValidation';
import {useState} from 'react';

function Example() {
  let [step, setStep] = useState<Key>('details');
  let [name, setName] = useState('');
  let [email, setEmail] = useState('');
  // Only focus the field when Save advances to the next step.
  let [focusField, setFocusField] = useState(false);

  // Each step is completed once its field is valid, in any order.
  let completedKeys: Key[] = [];
  if (isValidName(name)) {
    completedKeys.push('details');
  }
  if (isValidEmail(email)) {
    completedKeys.push('members');
  }

  return (
    <Wizard
      selectedKey={step}
      onSelectionChange={key => {
        setStep(key);
        setFocusField(false);
      }}
      allowsSelectingIncompleteSteps
      completedKeys={completedKeys}
    >
      <WizardStepList aria-label="Create project">
        <WizardStep id="details">Details</WizardStep>
        <WizardStep id="members">Members</WizardStep>
        <WizardStep id="review">Review</WizardStep>
      </WizardStepList>
      <WizardPanels>
        <WizardPanel id="details">
          <NameField value={name} onChange={setName} autoFocus={focusField} />
        </WizardPanel>
        <WizardPanel id="members">
          <EmailField value={email} onChange={setEmail} autoFocus={focusField} />
        </WizardPanel>
        <WizardPanel id="review">
          <Summary name={name} email={email} />
        </WizardPanel>
      </WizardPanels>
      <div className="wizard-buttons">
        <Button slot="previous" variant="secondary">Back</Button>
        {step === 'review'
          ? <Button isDisabled={completedKeys.length < 2} onPress={() => alert(`Created ${name}!\nEmail: ${email}`)}>Create project</Button>
          : <Button slot="next" onPress={() => setFocusField(true)}>Next</Button>}
      </div>
    </Wizard>
  );
}

API

<Wizard>
  <WizardStepList>
    <WizardStep />
  </WizardStepList>
  <WizardPanels>
    <WizardPanel />
  </WizardPanels>
  <Button slot="previous" />
  <Button slot="next" />
</Wizard>

Wizard

A Wizard guides users through a multi-step process one step at a time, and allows them to navigate between the steps they have reached.

NameTypeDefault
childrenReactNodeDefault: —

The children of the component (a WizardStepList and optional WizardPanels). Buttons with slot="previous" and slot="next" move to the previous and next steps.

completedKeysIterable<Key>Default: —

The keys of the completed steps. The application decides when a step is completed, for example, when all its fields are valid. Unless allowsSelectingIncompleteSteps is set, any step up to and including the step immediately following the last completed step is navigable, and the next button only moves to navigable steps. When omitted, the steps before the current step are considered completed. If allowsSelectingIncompleteSteps is set, no steps are considered completed.

allowsSelectingIncompleteStepsbooleanDefault: —

Whether every step that is not in disabledKeys is navigable at any time, rather than only the steps up to and including the one after the last completed step.

orientationDefault: 'horizontal'

The orientation of the wizard.

isDisabledbooleanDefault: —

Whether the wizard step list is disabled.

selectedKeyKey | nullDefault: —

The currently selected step (controlled).

defaultSelectedKeyKeyDefault: —

The initially selected step (uncontrolled).

onSelectionChange(key: Key) => voidDefault: —

Handler called when the selected step changes.

disabledKeysIterable<Key>Default: —

The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.

Default className: react-aria-Wizard

Render PropCSS Selector
orientationCSS Selector: [data-orientation="horizontal | vertical"]
The orientation of the wizard.

WizardStepList

A WizardStepList groups the steps within a <Wizard>. The ids of its steps must match up with a corresponding <WizardPanel> inside the <WizardPanels>.

NameType
childrenReactNode | (item: object) => ReactNode

The contents of the collection.

itemsIterable<object>

Item objects in the collection.

dependenciesReadonlyArray<any>

Values that should invalidate the item cache when using dynamic collections.

Default className: react-aria-WizardStepList

Render PropCSS Selector
orientationCSS Selector: [data-orientation="horizontal | vertical"]
The orientation of the wizard step list.
stateCSS Selector: —
State of the wizard step list.

WizardStep

A WizardStep represents an individual step within a <WizardStepList>.

NameType
children<>

The children of the component. A function may be provided to alter the children based on component state.

idKey

The unique id of the step.

isDisabledboolean

Whether the step is disabled.

Default className: react-aria-WizardStep

Render PropCSS Selector
isHoveredCSS Selector: [data-hovered]
Whether the step is currently hovered with a mouse.
isPressedCSS Selector: [data-pressed]
Whether the step is currently in a pressed state.
isSelectedCSS Selector: [data-selected]
Whether the step is currently selected.
isFocusedCSS Selector: [data-focused]
Whether the step is currently focused.
isFocusVisibleCSS Selector: [data-focus-visible]
Whether the step is currently keyboard focused.
isDisabledCSS Selector: [data-disabled]
Whether the step is disabled.
isCurrentCSS Selector: [data-current]
Whether the step is the current step.
isCompletedCSS Selector: [data-completed]
Whether the step is completed.
stepNumberCSS Selector: —
The position of the step within the WizardStepList, starting from 1.

WizardPanels

Groups multiple <WizardPanel> elements, and provides CSS variables for animated transitions.

NameType
childrenReactNode | (item: object) => ReactNode

The contents of the collection.

itemsIterable<object>

Item objects in the collection.

dependenciesReadonlyArray<any>

Values that should invalidate the item cache when using dynamic collections.

Default className: react-aria-WizardPanels

CSS Variable
--tab-panel-width
The width of the active panel in pixels. Useful for animations. Set when width, inline-size, or all is used in the CSS transition.
--tab-panel-height
The height of the active panel in pixels. Useful for animations. Set when height, block-size, or all is used in the CSS transition.

WizardPanel

A WizardPanel provides the content for a step.

NameTypeDefault
children<>Default: —

The children of the component. A function may be provided to alter the children based on component state.

idKeyDefault: —

The unique id of the corresponding step.

shouldForceMountbooleanDefault: false

Whether to mount the wizard panel in the DOM even when it is not currently selected. Inactive panels are inert and cannot be interacted with. They must be styled appropriately so this is clear to the user visually.

Default className: react-aria-WizardPanel

Render PropCSS Selector
isFocusedCSS Selector: [data-focused]
Whether the wizard panel is currently focused.
isFocusVisibleCSS Selector: [data-focus-visible]
Whether the wizard panel is currently keyboard focused.
isInertCSS Selector: [data-inert]
Whether the wizard panel is currently non-interactive. This occurs when the shouldForceMount prop is true, and the corresponding step is not selected.
isEnteringCSS Selector: [data-entering]
Whether the wizard panel is currently entering. Use this to apply animations.
isExitingCSS Selector: [data-exiting]
Whether the wizard panel is currently exiting. Use this to apply animations.
stateCSS Selector: —
State of the wizard step list.