Skip to main content

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

    NameTypeDefaultDescription
    persist?
    false

    Keeps the store when the Stepper unmounts. The app then calls resetStepData() to clear values and statuses itself.

    Stepper​

    The Stepper renders the step list, the content of the current step, and the footer.

    StepperProps

    extends
    NameTypeDefaultDescription
    children?

    One or more Stepper.Step elements with unique ids.

    Only Stepper.Step elements that are direct children are rendered. A step inside a Fragment or returned by a wrapper component is ignored. In development, the Stepper logs a warning for ignored elements and for duplicate ids.

    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 goToStep().

    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 undefined goes to the first invalid step, if any. Throw a StepperRefusal to stay on the step and mark it invalid. Any other error is reported and the step stays as it is.

    StepperNavigationPayload

    NameTypeDefaultDescription
    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

    NameTypeDefaultDescription
    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

    NameTypeDefaultDescription
    id
    keyof T &

    The invalid step.

    required

    false when the step is marked optional.

    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

    extends<, | | >
    NameTypeDefaultDescription
    id

    Stable identifier of the step, used as the store key. Must be unique within the Stepper.

    children?

    Step content. Typically Stepper.Title, Stepper.Description, Stepper.Hint, Stepper.ErrorMessage and Stepper.Content.

    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 undefined to keep the default verdict. Throw a StepperRefusal to stay on the step and mark it invalid. Any other error is reported and the step stays as it is.

    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

    NameTypeDefaultDescription
    step?
    K

    Narrows name and the value type. The field always belongs to the enclosing step.

    name
    N

    Identifies the field within its step.

    children
    (field: <<T, K, N>>) =>

    Render function that receives the field and returns the control.

    StepperControlField

    NameTypeDefaultDescription
    name

    The field name, without any step prefix.

    value
    V |

    The current value in the store. null while the store holds no value.

    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

    NameTypeDefaultDescription
    currentStepId
    keyof T &

    The id of the active step.

    stepIds
    <keyof T & >

    Ids of the steps currently in the flow, in navigation order.

    isValid

    true when no step in the flow has status.validity === 'invalid'.

    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 onStepSelected.

    setStepData
    <K extends keyof T & >(stepId: K, update: <T[K]> | ((prev: <T[K]>) => <T[K]>)) =>

    Updates status, values or both for a step. values is shallow-merged.

    resetStepData
    (stepId?: keyof T & ) =>

    Returns one step, or every step in the flow when stepId is omitted, to its initialState and clears the status. Fields missing from initialState return to null. A step without initialState keeps its values. Does not navigate. Call it yourself when the store is created with persist: true.

    StepData

    NameTypeDefaultDescription
    status?

    Validation status of the step. undefined while unset.

    values

    Values of the step.

    StepDataUpdate

    NameTypeDefaultDescription
    status?

    Replaces the step's status. Pass undefined to clear it. Omit the key to keep the current status.

    values?
    <>

    Values to shallow-merge into the step's values.

    StepStatus

    NameTypeDefaultDescription
    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

    NameTypeDefaultDescription
    id?
    K

    The step to read and write. Defaults to the enclosing Stepper.Step. Pass it to access another step's data, also from outside a Stepper.Step.

    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 resetStepData returns the step to the value from that first render. To fill in data that loads later, use setValues instead.

    It never overwrites a value already in the store. Fields it does not name start as null. Applies to the step named by id. If several useStep calls name the same step, pass initialState in only one of them.

    UseStepResult

    NameTypeDefaultDescription
    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

    extends
    NameTypeDefaultDescription
    steps
    []

    The steps to display, in order. Each step needs a unique id.

    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. 'auto' adapts to the container width. ArrowUp and ArrowLeft move to the previous step, ArrowDown and ArrowRight to the next, in every layout. Outside a Stepper, 'auto' and 'horizontal' measure a wrapper that fills the parent, so the parent needs a definite width (a shrink-to-fit parent collapses it).

    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

    extends<, | | >
    NameTypeDefaultDescription
    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 validity is 'invalid'. Without a message, the hint stays visible.

    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 'pending' or 'aborted', the step shows the neutral look of a step that has not been validated yet.

    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

    extends
    NameTypeDefaultDescription
    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

    extends
    NameTypeDefaultDescription
    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 true, shows a loading spinner on the primary button (Next, or Finish on the last step), announces "Loading" and ignores presses on it. The button hides its label while loading and stays in the tab sequence. The Back button stays active, so the consumer must handle onBack while a request is pending, for example by aborting it.

    onBack?
    () =>

    Called when the user clicks Back.

    onNext?
    () =>

    Called when the user clicks Next.

    onComplete?
    () =>

    Called when the user clicks Finish.

    Still have questions?
    Find answers in the Dynatrace Community