When to use it#
- Use it at the top of each page of a form that takes several pages, directly after the page heading.
- Count sections, not pages, so an answer that adds a page never changes the total. If you can’t count the sections reliably, leave it out: never “Step 3 of ?”.
- Not on a start page, a confirmation page, an exit page or a form with one page.
- Not for moving between steps: it has no links. Going back is a Back link, made with a Link. The check-answers page can use a DefinitionList with a Change link for each answer.
Example#
Which vehicle is the permit for?
Step 2 of 5: Your vehicle
import { Heading, Stepper } from '@kvirn-ui/react'
import { useStepperTexts } from './texts.ts'
export function DefaultStepper() {
const { texts } = useStepperTexts()
return (
<div>
<Heading as="h4">{texts.heading}</Heading>
<Stepper current={2} total={5} name={texts.sectionName} />
</div>
)
}Use cases#
A page with a question in an application
A step is a section, and a section can take more than one page. This page asks for the registration number and is one page of “Your vehicle”, so it says step 2 of 5. The name is optional: without one the text is “Step 2 of 5”.
import { Button, Field, Heading, Stack, Stepper, TextInput } from '@kvirn-ui/react'
import { useStepperTexts } from './texts.ts'
export function QuestionPage() {
const { texts } = useStepperTexts()
return (
<form
onSubmit={(event) => {
// A real form saves the answer and goes to the next page from here.
event.preventDefault()
}}
>
<Field.Root>
<Stack className="kv-stack--gap-2">
{/* An h1 on a real page: the docs page has its own h1, so the levels here stay below it. */}
<Heading as="h4">
<Field.Label className="kv-field-label--heading">
{texts.registrationNumber}
</Field.Label>
</Heading>
<Stepper current={2} total={5} name={texts.sectionName} />
</Stack>
<TextInput name="registration-number" />
</Field.Root>
<Button type="submit" className="kv-button--primary">
{texts.continue}
</Button>
</form>
)
}Props in this example:
An application that moves from section to section
The numbers come from your flow, so the text changes with each step and stays in the same place on every page. Focus moves to the new page’s heading, and the answers are kept when the person goes back. On the last step the example shows a page without a Stepper, as a confirmation should. Here Back is a button, because the example keeps its state on one page. On a real site it is a Back link.
import { Button, Field, Heading, Stack, Stepper, TextInput, useRouteFocus } from '@kvirn-ui/react'
import { useRef, useState } from 'react'
import { useStepperTexts } from './texts.ts'
export function ApplicationFlow() {
const { texts } = useStepperTexts()
const { sections } = texts
const [index, setIndex] = useState(0)
const [answers, setAnswers] = useState<string[]>(() => sections.map(() => ''))
const [isSent, setIsSent] = useState(false)
const pageRef = useRef<HTMLDivElement>(null)
// The docs page already has an h1, so this example uses an h4. On your pages the default is h1.
useRouteFocus({ key: isSent ? 'sent' : String(index), containerRef: pageRef, selector: 'h4' })
const section = sections[index]
const isLast = index === sections.length - 1
return (
<div ref={pageRef}>
{isSent || section === undefined ? (
<Stack className="kv-stack--gap-4">
<Heading as="h4">{texts.sentTitle}</Heading>
<p>{texts.sentBody}</p>
<div>
<Button
onClick={() => {
setAnswers(sections.map(() => ''))
setIndex(0)
setIsSent(false)
}}
>
{texts.startAgain}
</Button>
</div>
</Stack>
) : (
<form
onSubmit={(event) => {
event.preventDefault()
if (isLast) {
setIsSent(true)
} else {
setIndex(index + 1)
}
}}
>
{/* The key remounts the field, so focus drops and useRouteFocus can move it to the heading. */}
<Field.Root key={index}>
<Stack className="kv-stack--gap-2">
<Heading as="h4">
<Field.Label className="kv-field-label--heading">{section.question}</Field.Label>
</Heading>
<Stepper current={index + 1} total={sections.length} name={section.name} />
</Stack>
<TextInput
name={section.field}
value={answers[index] ?? ''}
onChange={(event) => {
const answer = event.currentTarget.value
setAnswers((current) => current.map((old, i) => (i === index ? answer : old)))
}}
/>
</Field.Root>
<p>
{index > 0 && (
<>
<Button type="button" onClick={() => setIndex(index - 1)}>
{texts.back}
</Button>{' '}
</>
)}
<Button type="submit" className="kv-button--primary">
{isLast ? texts.send : texts.continue}
</Button>
</p>
</form>
)}
</div>
)
}Props in this example:
Warning: Don't forget
Moving focus to the new page’s heading is the flow’s work, here with useRouteFocus. The Stepper is not a Tab stop and says nothing by itself when the step changes (2.4.3 Focus Order, level A). Put it in the same place on every step (3.2.3 Consistent Navigation, level AA).
A page with a choice between options
When the question is a group of options, the legend is the page’s heading. Put the Stepper straight after the legend, outside it, so it is not read as part of the group’s name.
import { Button, Field, RadioGroup, Stepper } from '@kvirn-ui/react'
import { useStepperTexts } from './texts.ts'
export function OptionsPage() {
const { texts } = useStepperTexts()
return (
<form
onSubmit={(event) => {
// A real form saves the answer and goes to the next page from here.
event.preventDefault()
}}
>
<RadioGroup.Root name="owner">
<RadioGroup.Legend className="kv-fieldset-legend--heading">
{/* An h1 on a real page: the docs page has its own h1, so the levels here stay below it. */}
<h4>{texts.owner.question}</h4>
</RadioGroup.Legend>
<Stepper current={2} total={5} name={texts.sectionName} />
<RadioGroup.Option>
<RadioGroup.Radio value="me" />
<Field.Label>{texts.owner.me}</Field.Label>
</RadioGroup.Option>
<RadioGroup.Option>
<RadioGroup.Radio value="company" />
<Field.Label>{texts.owner.company}</Field.Label>
</RadioGroup.Option>
<RadioGroup.Option>
<RadioGroup.Radio value="family" />
<Field.Label>{texts.owner.family}</Field.Label>
</RadioGroup.Option>
</RadioGroup.Root>
<Button type="submit" className="kv-button--primary">
{texts.continue}
</Button>
</form>
)
}Props in this example:
With your own element
When the markup is yours, spread the props from the hook on your own element, and render the text from the hook right after the page heading. You can use the same text in the page title.
Which vehicle is the permit for?
Step 2 of 5: Your vehicle
import { Heading, useStepper } from '@kvirn-ui/react'
import { useStepperTexts } from './texts.ts'
export function OwnMarkup() {
const { texts } = useStepperTexts()
const stepper = useStepper({ current: 2, total: 5, name: texts.sectionName })
return (
<div>
{/* An h1 on a real page: the docs page has its own h1, so the levels here stay below it. */}
<Heading as="h4">{texts.heading}</Heading>
<p {...stepper.rootProps}>{stepper.text}</p>
</div>
)
}Props in this example:
currenton useStepper (options)totalon useStepper (options)rootPropson useStepper (result)texton useStepper (result)
Accessibility#
What it does for you#
- APG pattern: none. Stepper is static text: native semantics only.
- Deviations: none.
- Native elements used:
<p>. The consumer can pick<div>withas(allowed elements below), and its own semantics apply.
Stepper says where the user is in a multi-page form: "Step 2 of 5: Your vehicle". It is orientation, not navigation. A step is a section that may span pages, so the total does not change when an answer adds a page. If sections can't be counted reliably, leave the Stepper out: never "Step 3 of ?".
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Stepper | <p> → implicit paragraph, no explicit role | none | class="kv-stepper". No data-*: it has no state. Attributes (id, aria-*) and the ref reach the element unchanged. The text is the message, never children |
| Stepper | as | the chosen element's own | One element, chosen with a string. A value outside the list is a type error and, in JS, warns once in development and renders the default element. The text is the message, never children |
| Stepper | never | no role, tabindex | No role="status", no aria-live, no aria-current, no list, no link, no aria-describedby from the heading: the text is one reading stop in the page's order |
useStepper | the same, for your own markup | text, element, rootProps | text can be reused, for example in <title> |
Rules the automated tests check:
- Placement. The Stepper is the next element after the page heading, outside the heading,
labelandlegend, so it never joins a control's or group's name (1.3.1 Info and Relationships, A; 1.3.2 Meaningful Sequence, A). In a label or legend that is the heading, it comes after theh1or thelegend, before the description and the control. - Text.
stepper.statuswithout aname,stepper.statusWithNamewith one. Each locale owns its word order and punctuation; numbers follow the language's number format. A blanknamecounts as none. - Dev warnings (once): a
currentortotalthat is not a positive whole number, or acurrentabovetotal; a Stepper rendered inside anh1–h6orrole="heading",label,legend,summary,button,aorcaption.
It announces nothing.
What you need to do#
- Count sections, not pages. The total stays the same when branching adds a page.
- Short names in plain words. Wrap, never truncate: long Finnish names hyphenate.
- Never navigation. No links to steps. Going back is a Back link, and Change links on the check-answers page keep answers (3.3.7 Redundant Entry, A).
- Focus order and consistency are the flow's work. The Stepper is no Tab stop, and focus moves to the new page's heading through
useRouteFocus(2.4.3 Focus Order, A). Put it in the same place on every step (3.2.3 Consistent Navigation, AA). Keep the answers when the user goes back (3.3.7 Redundant Entry, A). - Not on a start page, a confirmation, an exit page or a one-page form.
- Language. Text in another language goes in a nested
KvirnProvider, withuseLocale().localePropson your own element (3.1.2 Language of Parts, AA).
Warning: Don't forget
Put the Stepper directly after the page heading, as its own element. Inside a heading, label or legend its text becomes part of that name (1.3.1 Info and Relationships, level A). A development warning says so.
Visual and modes#
Headless: Stepper ships no CSS. With the default theme the Stepper is body text in the normal text colour. It has no margin (the page layout sets the spacing), it wraps and hyphenates long words, and it looks the same in every density. It adds no new colour pair: the text colour on the page backgrounds is already measured (1.4.3 Contrast (Minimum), AA). Sizes follow the browser's text size (1.4.4 Resize Text, AA), and the text reflows at 320px (1.4.10 Reflow, AA). Text spacing (1.4.12 Text Spacing, AA) is checked by the text-spacing sweep, which looks for clipped text. Forced colours: it uses the system text colour, and nothing is carried by colour (1.4.1 Use of Color, A). Target size, focus indicator and motion do not apply, because Stepper is not a control.
Focus management#
- Initial focus: not moved. Stepper never moves focus.
- Trap: no.
- Restore to: not applicable.
- On a step change the flow moves focus (
useRouteFocusto theh1; the ErrorSummary after a failed submit). The Stepper is the next item in reading order.
Allowed elements#
A tag outside the list changes the page's outline or semantics (1.3.1 Info and Relationships, A; 4.1.2 Name, Role, Value, A). as is a string, so it works from a Server Component.
| Part | `as` | Why |
|---|---|---|
| Stepper | p (default), div | A line of text. No span (it would sit inline in a heading, which the placement check forbids), no heading and no list. A value outside the list is a type error and, in JS, warns once in development and renders the default element. |
WCAG success criteria#
- 1.3.1 Info and Relationships (A), 1.3.2 Meaningful Sequence (A): a paragraph that follows the heading, outside any name. Tests prove it is the reading stop right after the heading, and that a Stepper inside a heading, label or legend warns.
- 1.4.1 Use of Color (A): the words say it, and axe finds no violation in any theme.
- 1.4.3 Contrast (Minimum) (AA), 1.4.4 Resize Text (AA), 1.4.10 Reflow (AA): text on measured pairs, in rem, wrapping. 1.4.12 Text Spacing (AA): the text-spacing sweep checks that no text is clipped.
Keyboard#
Stepper has no keys of its own. What you put in it keeps its own keys.
Announcements#
What a screen reader reads#
| State or action | Read aloud | Politeness | Test |
|---|---|---|---|
| A question page read top to bottom | heading, Which vehicle is the permit for?, level 1 → paragraph → Step 2 of 5: Your vehicle | none | stepper.test.tsx › is the reading stop right after the heading |
| Without a name, or a blank name | paragraph → Step 2 of 5, no colon | none | stepper.test.tsx › reads without a name and with a blank name as the position alone |
| Label or legend as the heading | the Stepper after the h1 or the legend, before the control: not read in that state | none | none (the placement is checked by the dev warnings only) |
API reference#
import { Stepper, useStepper } from '@kvirn-ui/react'Stepper
Renders <p> with no role of its own, or a <div> with as. The text is the message, so it takes no children. It takes every attribute of the element it renders and passes ref to it. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
current | number | Required | The step the user is on: a positive whole number, at most total. |
total | number | Required | How many steps there are: a positive whole number. Count sections, so an answer that adds a page never changes it. |
name | string | – | The section’s name, in plain words: “Your vehicle”. A blank name counts as none. |
messages | Partial<KvirnMessages['stepper']> | – | Replaces stepper.status and stepper.statusWithName for this instance. |
as | 'p' | 'div' | 'p' | Changes the element. It is a line of text: no span, no heading and no list. A string, so it works from a Server Component. |
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-stepper | always | The part class. The default theme styles it. Stepper has no state, so no data-*. |
useStepper
Options
| Prop | Type | Default | Description |
|---|---|---|---|
current | number | Required | The step the user is on: a positive whole number, at most total. |
total | number | Required | How many steps there are: a positive whole number. Count sections, so an answer that adds a page never changes it. |
name | string | – | The section’s name, in plain words: “Your vehicle”. A blank name counts as none. |
messages | Partial<KvirnMessages['stepper']> | – | Replaces stepper.status and stepper.statusWithName for this instance. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
text | string | – | The words, for example “Step 2 of 5: Your vehicle”. Reuse them in <title> if you like. |
element | 'p' | – | The element to render: always p. |
rootProps | StepperPartProps | – | Spread on your element: the class, and a ref that checks in development that it is not inside a heading, label, legend, summary, button, link or caption. Pass the ref on if you set your own. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one Stepper, pass its messages prop.
stepper.status
The text without a name. Each language owns its word order.
| Language | Default text |
|---|---|
| Svenska | Steg 2 av 5 |
| Suomi | Vaihe 2/5 |
| Norsk bokmål | Steg 2 av 5 |
| Norsk nynorsk | Steg 2 av 5 |
| English | Step 2 of 5 |
stepper.statusWithName
The text with the section’s name.
| Language | Default text |
|---|---|
| Svenska | Steg 2 av 5: Your vehicle |
| Suomi | Vaihe 2/5: Your vehicle |
| Norsk bokmål | Steg 2 av 5: Your vehicle |
| Norsk nynorsk | Steg 2 av 5: Your vehicle |
| English | Step 2 of 5: Your vehicle |
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | stepper.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | stepper.test.tsx › renders one p with the position and a class, no role or ARIA, and passes attributes and the ref through; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | stepper.test.tsx › keyboard › Tab passes over it |
| Focus order and management | n/a | n/a | n/a | nothing focusable: the component never takes or moves focus |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pass | n/a | pass | the four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
What to check#
- Read from the heading to the next item: you hear one paragraph, "Step 2 of 5: Your vehicle". Tab skips it.