Skip to main content

StepperForm

ComplexForms<co-stepper-form>

StepperForm runs a multi-step form such as the 7-step Add Patient, with the step bar, an error summary and Back, Next and Save buttons.

import { StepperForm } from 'health-components';

Examples​

Add Patient​

Storybook

Last Step Saving​

Storybook

Usage​

<StepperForm title="Add Patient" finishLabel="Save Patient" onFinish={save}
steps={[{ label: "Demographics", content: <DemographicsFields/> }, { label: "Insurance", content: <InsuranceFields/>, error: true }]} />

When to use​

  • Forms with 3 to 8 sections that must be done in order.

When not to use​

  • Edits to one section of an existing record: a Card with Save.

Variants and states​

VariantWhat it is
stepsAny number; each has label, content and an error flag.
error summaryAlert above the fields.
save draftExtra button when onSaveDraft is set.
finishLast step shows the finish label.

Accessibility​

  • Step text "Step 4 of 7 . Guarantor" in the card subtitle.
  • Next button names the next step.

Do and don't​

  • Do: Keep entered data when going Back.
  • Don't: Validate a step only at the end.

Props​

PropTypeDefaultDescription
title *string—Card title and accessible name of the step bar ("Add Patient"); required
steps *StepperFormStep[]—Array<{label, content: node, error?}>; required
currentnumberuncontrolledCurrent step, 0-based (controlled)
defaultCurrentnumber0Initial step, 0-based (uncontrolled)
finishLabelstring"Save"Label of the finish button on the last step
errorSummaryReactNodenoneError summary shown in an Alert above the fields
savingbooleanfalseFinish button shows a spinner
onStep(index: number) => voidnoneCalled with the new step index on Next and Back
onFinish() => voidnoneFinish button on the last step
onCancel() => voidnoneCancel button
onSaveDraft() => voidnoneShows a Save Draft button that calls this

Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, plus className and event handlers on the root element.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-stepper-form>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.

Angular template
<co-stepper-form title="…" current="…" [steps]="steps" (co-step)="onStep($event.detail)"></co-stepper-form>
KindNameDescription
attributetitleCard title and accessible name of the step bar ("Add Patient"); required
property / JSON attributestepsArray<{label, content: node, error?}>; required
attributecurrentCurrent step, 0-based (controlled); default uncontrolled
attributedefault-current / defaultCurrentInitial step, 0-based (uncontrolled); default 0
attributefinish-label / finishLabelLabel of the finish button on the last step; default "Save"
attributesavingFinish button shows a spinner; default false
attributedefault-checked / defaultChecked
property / JSON attributedefault-value / defaultValue
attributeauto-focus / autoFocus
eventco-stepCalled with the new step index on Next and Back; default none (React: onStep)
eventco-finishFinish button on the last step; default none (React: onFinish)
eventco-cancelCancel button; default none (React: onCancel)
eventco-save-draftShows a Save Draft button that calls this; default none (React: onSaveDraft)
sloterror-summaryError summary shown in an Alert above the fields; default none Plain text also works as the `error-summary` attribute.