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
Last Step Saving
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
| Variant | What it is |
|---|---|
| steps | Any number; each has label, content and an error flag. |
| error summary | Alert above the fields. |
| save draft | Extra button when onSaveDraft is set. |
| finish | Last 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
| Prop | Type | Default | Description |
|---|---|---|---|
title * | string | — | Card title and accessible name of the step bar ("Add Patient"); required |
steps * | StepperFormStep[] | — | Array<{label, content: node, error?}>; required |
current | number | uncontrolled | Current step, 0-based (controlled) |
defaultCurrent | number | 0 | Initial step, 0-based (uncontrolled) |
finishLabel | string | "Save" | Label of the finish button on the last step |
errorSummary | ReactNode | none | Error summary shown in an Alert above the fields |
saving | boolean | false | Finish button shows a spinner |
onStep | (index: number) => void | none | Called with the new step index on Next and Back |
onFinish | () => void | none | Finish button on the last step |
onCancel | () => void | none | Cancel button |
onSaveDraft | () => void | none | Shows 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>
| Kind | Name | Description |
|---|---|---|
| attribute | title | Card title and accessible name of the step bar ("Add Patient"); required |
| property / JSON attribute | steps | Array<{label, content: node, error?}>; required |
| attribute | current | Current step, 0-based (controlled); default uncontrolled |
| attribute | default-current / defaultCurrent | Initial step, 0-based (uncontrolled); default 0 |
| attribute | finish-label / finishLabel | Label of the finish button on the last step; default "Save" |
| attribute | saving | Finish button shows a spinner; default false |
| attribute | default-checked / defaultChecked | |
| property / JSON attribute | default-value / defaultValue | |
| attribute | auto-focus / autoFocus | |
| event | co-step | Called with the new step index on Next and Back; default none (React: onStep) |
| event | co-finish | Finish button on the last step; default none (React: onFinish) |
| event | co-cancel | Cancel button; default none (React: onCancel) |
| event | co-save-draft | Shows a Save Draft button that calls this; default none (React: onSaveDraft) |
| slot | error-summary | Error summary shown in an Alert above the fields; default none Plain text also works as the `error-summary` attribute. |