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.
Wizard vs. ProgressList
Wizard if any of the steps need to be interactive. Otherwise, use a ProgressList to show the user's progress through steps.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.
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.
Accessibility
aria-label or aria-labelledby on the WizardStepList that describes the process, such as "Sign up". Each step announces whether it is completed, so hide visual indicators such as step numbers and checkmarks with aria-hidden.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.
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.
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.
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.
| Name | Type | Default |
|---|---|---|
children | ReactNode | Default: — |
The children of the component (a | ||
completedKeys | Iterable | 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 | boolean | Default: — |
Whether every step that is not in | ||
orientation | Orientation | Default: 'horizontal'
|
The orientation of the wizard. | ||
isDisabled | boolean | Default: — |
Whether the wizard step list is disabled. | ||
selectedKey | Key | null | Default: — |
The currently selected step (controlled). | ||
defaultSelectedKey | Key | Default: — |
The initially selected step (uncontrolled). | ||
onSelectionChange | | Default: — |
Handler called when the selected step changes. | ||
disabledKeys | Iterable | Default: — |
The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with. | ||
style | StyleOrFunction | Default: — |
The inline style for the element. A function may be provided to compute the style based on component state. | ||
className | ClassNameOrFunction | Default: 'react-aria-Wizard'
|
The CSS className for the element. A function may be provided to compute the class based on component state. | ||
id | string | Default: — |
The element's unique identifier. See MDN. | ||
aria-label | string | Default: — |
Defines a string value that labels the current element. | ||
aria-labelledby | string | Default: — |
Identifies the element (or elements) that labels the current element. | ||
aria-describedby | string | Default: — |
Identifies the element (or elements) that describes the object. | ||
aria-details | string | Default: — |
Identifies the element (or elements) that provide a detailed, extended description for the object. | ||
slot | string | null | Default: — |
A slot name for the component. Slots allow the component to receive props from a parent
component. An explicit | ||
render | DOMRenderFunction | Default: — |
Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements:
| ||
Default className: react-aria-Wizard
| Render Prop | CSS Selector |
|---|---|
orientation | CSS 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>.
| Name | Type | |
|---|---|---|
children | ReactNode | | |
The contents of the collection. | ||
items | Iterable | |
Item objects in the collection. | ||
dependencies | ReadonlyArray | |
Values that should invalidate the item cache when using dynamic collections. | ||
style | StyleOrFunction | |
The inline style for the element. A function may be provided to compute the style based on component state. | ||
className | ClassNameOrFunction | |
The CSS className for the element. A function may be provided to compute the class based on component state. | ||
aria-label | string | |
Defines a string value that labels the current element. | ||
aria-labelledby | string | |
Identifies the element (or elements) that labels the current element. | ||
aria-describedby | string | |
Identifies the element (or elements) that describes the object. | ||
aria-details | string | |
Identifies the element (or elements) that provide a detailed, extended description for the object. | ||
render | DOMRenderFunction | |
Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements:
| ||
Default className: react-aria-WizardStepList
| Render Prop | CSS Selector |
|---|---|
orientation | CSS Selector: [data-orientation="horizontal | vertical"]
|
| The orientation of the wizard step list. | |
state | CSS Selector: — |
| State of the wizard step list. | |
WizardStep
A WizardStep represents an individual step within a <WizardStepList>.
| Name | Type | |
|---|---|---|
children | ChildrenOrFunction | |
The children of the component. A function may be provided to alter the children based on component state. | ||
id | Key | |
The unique id of the step. | ||
isDisabled | boolean | |
Whether the step is disabled. | ||
onHoverStart | | |
Handler that is called when a hover interaction starts. | ||
onHoverEnd | | |
Handler that is called when a hover interaction ends. | ||
onHoverChange | | |
Handler that is called when the hover state changes. | ||
onFocus | | |
Handler that is called when the element receives focus. | ||
onBlur | | |
Handler that is called when the element loses focus. | ||
onFocusChange | | |
Handler that is called when the element's focus status changes. | ||
onPress | | |
Handler that is called when the press is released over the target. | ||
onPressStart | | |
Handler that is called when a press interaction starts. | ||
onPressEnd | | |
Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. | ||
onPressChange | | |
Handler that is called when the press state changes. | ||
onPressUp | | |
Handler that is called when a press is released over the target, regardless of whether it started on the target or not. | ||
onClick | | |
Not recommended – use | ||
href | Href | |
A URL to link to. See MDN. | ||
hrefLang | string | |
Hints at the human language of the linked URL. SeeMDN. | ||
target | HTMLAttributeAnchorTarget | |
The target window for the link. See MDN. | ||
rel | string | |
The relationship between the linked resource and the current page. See MDN. | ||
download | boolean | string | |
Causes the browser to download the linked URL. A string may be provided to suggest a file name. See MDN. | ||
ping | string | |
A space-separated list of URLs to ping when the link is followed. See MDN. | ||
referrerPolicy | HTMLAttributeReferrerPolicy | |
How much of the referrer to send when following the link. See MDN. | ||
routerOptions | RouterOptions | |
Options for the configured client side router. | ||
style | StyleOrFunction | |
The inline style for the element. A function may be provided to compute the style based on component state. | ||
className | ClassNameOrFunction | |
The CSS className for the element. A function may be provided to compute the class based on component state. | ||
aria-label | string | |
Defines a string value that labels the current element. | ||
aria-labelledby | string | |
Identifies the element (or elements) that labels the current element. | ||
aria-describedby | string | |
Identifies the element (or elements) that describes the object. | ||
aria-details | string | |
Identifies the element (or elements) that provide a detailed, extended description for the object. | ||
render | | |
Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Note: You can check if Requirements:
| ||
Default className: react-aria-WizardStep
| Render Prop | CSS Selector |
|---|---|
isHovered | CSS Selector: [data-hovered]
|
| Whether the step is currently hovered with a mouse. | |
isPressed | CSS Selector: [data-pressed]
|
| Whether the step is currently in a pressed state. | |
isSelected | CSS Selector: [data-selected]
|
| Whether the step is currently selected. | |
isFocused | CSS Selector: [data-focused]
|
| Whether the step is currently focused. | |
isFocusVisible | CSS Selector: [data-focus-visible]
|
| Whether the step is currently keyboard focused. | |
isDisabled | CSS Selector: [data-disabled]
|
| Whether the step is disabled. | |
isCurrent | CSS Selector: [data-current]
|
| Whether the step is the current step. | |
isCompleted | CSS Selector: [data-completed]
|
| Whether the step is completed. | |
stepNumber | CSS Selector: — |
The position of the step within the WizardStepList, starting from 1. | |
WizardPanels
Groups multiple <WizardPanel> elements, and provides CSS variables for animated transitions.
| Name | Type | |
|---|---|---|
children | ReactNode | | |
The contents of the collection. | ||
items | Iterable | |
Item objects in the collection. | ||
dependencies | ReadonlyArray | |
Values that should invalidate the item cache when using dynamic collections. | ||
style | CSSProperties | |
The inline style for the element. | ||
className | string | |
The CSS className for the element. | ||
render | DOMRenderFunction | |
Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements:
| ||
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.
| Name | Type | Default |
|---|---|---|
children | ChildrenOrFunction | Default: — |
The children of the component. A function may be provided to alter the children based on component state. | ||
id | Key | Default: — |
The unique id of the corresponding step. | ||
shouldForceMount | boolean | Default: 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. | ||
style | StyleOrFunction | Default: — |
The inline style for the element. A function may be provided to compute the style based on component state. | ||
className | ClassNameOrFunction | Default: 'react-aria-WizardPanel'
|
The CSS className for the element. A function may be provided to compute the class based on component state. | ||
aria-label | string | Default: — |
Defines a string value that labels the current element. | ||
aria-labelledby | string | Default: — |
Identifies the element (or elements) that labels the current element. | ||
aria-describedby | string | Default: — |
Identifies the element (or elements) that describes the object. | ||
aria-details | string | Default: — |
Identifies the element (or elements) that provide a detailed, extended description for the object. | ||
render | DOMRenderFunction | Default: — |
Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements:
| ||
Default className: react-aria-WizardPanel
| Render Prop | CSS Selector |
|---|---|
isFocused | CSS Selector: [data-focused]
|
| Whether the wizard panel is currently focused. | |
isFocusVisible | CSS Selector: [data-focus-visible]
|
| Whether the wizard panel is currently keyboard focused. | |
isInert | CSS 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. | |
isEntering | CSS Selector: [data-entering]
|
| Whether the wizard panel is currently entering. Use this to apply animations. | |
isExiting | CSS Selector: [data-exiting]
|
| Whether the wizard panel is currently exiting. Use this to apply animations. | |
state | CSS Selector: — |
| State of the wizard step list. | |