Stepper
Use the Stepper component for a multistep flow in a fixed order, such as a creation wizard. It gives users an overview of all steps and guides them through the steps one by one. Create it with createStepper.
createStepper
createStepper returns the Stepper component, the useStepper hook, and the useStep hook, all bound to one store. Pass the step values as a type parameter to type step ids and fields.
CreateStepperOptions
| Name | Type | Default | Description |
|---|---|---|---|
persist? | false | Keeps the store when the |
Stepper
The Stepper renders the step list, the content of the current step, and the footer.
StepperProps
| Name | Type | Default | Description |
|---|---|---|---|
children? | | One or more Only | |
defaultStepId? | keyof T & | first step in declaration order | The step the wizard starts on. |
onStepSelected? | (payload: <T>) => | | Called after the user selects a step in the navigation and the step has
changed. Never fires for Next, Back or |
onComplete? | (payload: <T>) => (keyof T & ) | | <(keyof T & ) | > | | Called when the user presses Finish, whether or not a step is invalid.
Return a step id to navigate there, or the current step id to handle it
yourself. Returning |
StepperNavigationPayload
| Name | Type | Default | Description |
|---|---|---|---|
currentStepId | keyof T & | | The step the user is leaving. |
nextStepId | keyof T & | | The step the user is going to. |
status? | | The departing step's status in the store. The key is always present. | |
snapshot | T | | Values of every step currently in the flow, keyed by step id. |
StepperCompletePayload
| Name | Type | Default | Description |
|---|---|---|---|
currentStepId | keyof T & | | The step the user completed from, always the last step in the flow. |
invalidSteps | <<T>> | | Every step in the flow with an invalid status, in navigation order. Empty when none. Required steps the user never visited are included. |
snapshot | T | | Values of every step currently in the flow, keyed by step id. |
StepperInvalidStep
| Name | Type | Default | Description |
|---|---|---|---|
id | keyof T & | | The invalid step. |
required | |
|
Stepper.Step
Use Stepper.Step to declare one step. Inside it, use Stepper.Title, Stepper.Description, Stepper.Hint, Stepper.ErrorMessage, and Stepper.Content to fill the step. Stepper.Hint and Stepper.ErrorMessage share one line in the step list. The Stepper shows the error message only while the step is invalid.
StepperStepProps
<, | | >| Name | Type | Default | Description |
|---|---|---|---|
id | | Stable identifier of the step, used as the store key. Must be unique within the Stepper. | |
children? | | Step content. Typically Only these elements are read, and only when they are direct children. Elements inside a Fragment or returned by a wrapper component are ignored. | |
onNext? | (payload: ) => | | < | > | | Called when the user presses Next on this step. Return a step id to
navigate there, or |
onBack? | (payload: ) => | | Called after the user pressed Back on this step and navigation completed. |
required? | true | Marks the step as required. An optional step never blocks Next. | |
disabled? | false | Blocks navigating to the step. |
Stepper.Control
Use Stepper.Control to connect a field to the values of the enclosing step. It renders no element of its own. It passes the field to a render function. Pass the value and onChange of the field to your input. The value is null while the store holds no value, so fall back to an empty string for inputs that need one.
StepperControlProps
| Name | Type | Default | Description |
|---|---|---|---|
step? | K | | Narrows |
name | N | | Identifies the field within its step. |
children | (field: <<T, K, N>>) => | | Render function that receives the field and returns the control. |
StepperControlField
| Name | Type | Default | Description |
|---|---|---|---|
name | | The field name, without any step prefix. | |
value | V | | | The current value in the store. |
onChange | (value: V) => | | Writes a new value to the store. |
StepperRefusal
Throw a StepperRefusal from onNext or onComplete to keep the user on the current step. The Stepper marks the step as invalid. The optional message is added to the errors of the step status, after the errors your app already set and without duplicates. Any other thrown error is a failure and does not change the status.
throw new StepperRefusal('The username is taken.');
useStepper
useStepper returns the store, or the part of it that your selector picks. It works inside and outside the Stepper.
StepperStore
| Name | Type | Default | Description |
|---|---|---|---|
currentStepId | keyof T & | | The id of the active step. |
stepIds | <keyof T & > | | Ids of the steps currently in the flow, in navigation order. |
isValid | |
| |
steps | {
[K in keyof T]: <T[K]>;
} | | Per-step state, keyed by step id. Also holds steps that left the flow. |
goToStep | (stepId: keyof T & ) => | | Navigates to a step. Bypasses reachability, does not validate and does not
fire |
setStepData | <K extends keyof T & >(stepId: K, update: <T[K]> | ((prev: <T[K]>) => <T[K]>)) => | | Updates |
resetStepData | (stepId?: keyof T & ) => | | Returns one step, or every step in the flow when |
StepData
| Name | Type | Default | Description |
|---|---|---|---|
status? | | Validation status of the step. | |
values | | Values of the step. |
StepDataUpdate
| Name | Type | Default | Description |
|---|---|---|---|
status? | | Replaces the step's status. Pass | |
values? | <> | | Values to shallow-merge into the step's values. |
StepStatus
| Name | Type | Default | Description |
|---|---|---|---|
validity | | Validity of the step. | |
errors | [] | | Errors that currently apply to the step. |
useStep
useStep reads and writes the values and the status of one step. Call it with a step id, with a config object, or with no argument inside a Stepper.Step.
UseStepConfig
| Name | Type | Default | Description |
|---|---|---|---|
id? | K | | The step to read and write. Defaults to the enclosing |
initialState? | <<T, K>> | \{\} | The step's initial values. Read once, on the first render of the step.
Later changes to this value are ignored, and It never overwrites a value already in the store. Fields it does not name
start as |
UseStepResult
| Name | Type | Default | Description |
|---|---|---|---|
id | K | | The id of the step the hook reads and writes. |
values | <T, K> | | The step's values. |
status? | | The step's status. | |
setValues | (update: <<T, K>> | ((prev: <T, K>) => <<T, K>>)) => | | Shallow-merges into the step's values. |
setStatus | (status: | ) => | | Writes the step's status. |
StepperNavigation
Use StepperNavigation, StepperPanel, and StepperFooter to build your own multistep flow without createStepper. They render from the props you pass and report user actions through callbacks. You own the current step, the validation, and what happens on Next or Finish.
StepperNavigation shows the steps as a list. It switches between a vertical list and a compact horizontal bar, depending on the available width, and supports keyboard navigation. It calls onNavigate when the user selects a step. It does not decide whether the user may go there, so check that in your handler. Only a disabled step cannot be selected.
StepperNavigationProps
| Name | Type | Default | Description |
|---|---|---|---|
steps | [] | | The steps to display, in order. Each step needs a unique |
currentStepId | | Identifier of the currently selected step. If no step matches, none is marked as current and the first step is the one reached with Tab. | |
orientation? | | | | 'auto' | Controls the navigation layout. |
onNavigate? | (stepId: ) => | | Callback fired with the step's id when the user selects a step. It also fires when the selected step is the current one, and never fires for disabled steps. |
StepDetails
<, | | >| Name | Type | Default | Description |
|---|---|---|---|
id | | Unique identifier of the step. | |
title? | | Step title. A tooltip shows the full title when it is truncated. | |
hint? | | Secondary text shown below the title. A tooltip shows the full text when it is truncated. | |
errorMessage? | | Message shown instead of the hint when | |
required? | false | Marks the step as required. Steps that are not required are labelled "Optional" in the navigation entry. | |
disabled? | false | Marks the step as disabled. The step stays focusable and is announced as disabled to assistive technology, but selecting it does nothing. | |
validity? | | Validation state shown on the step indicator. Without a value, or while
|
Validity
Signature:
export declare type Validity = | | | ;StepperPanel
StepperPanel holds the content of one step. An inactive panel stays mounted but hidden, so the fields of other steps keep their values and their validation.
StepperPanelProps
| Name | Type | Default | Description |
|---|---|---|---|
isActive? | false | Whether this panel is the currently active step. A panel that is not active stays mounted but is hidden and not interactive. | |
title? | | Step title, rendered in the panel heading. It also names the panel for assistive technology. | |
description? | | Optional description rendered below the title. | |
children? | | Main panel body content. |
StepperFooter
StepperFooter shows the step counter and the Back, Next, and Finish buttons. It hides Back on the first step and shows Finish instead of Next on the last step.
StepperFooterProps
| Name | Type | Default | Description |
|---|---|---|---|
currentStepIndex | | Zero-based index of the current step. Drives the "Step X of Y" counter. Back is hidden on the first step and Next is hidden on the last step. | |
totalSteps | | Total number of steps. | |
isPending? | false | When | |
onBack? | () => | | Called when the user clicks Back. |
onNext? | () => | | Called when the user clicks Next. |
onComplete? | () => | | Called when the user clicks Finish. |