Skip to
Keyboard shortcuts

Use the up and down arrow keys to move between items. Press Alt+Shift+K to open this list again.

Alpha version out now. The API may still change.

Stepper

Says where the user is in a multi-page form, as one line of text: “Step 2 of 5: Your vehicle”. Tells someone which step of a form with several pages they are on, in plain text such as “Step 2 of 5: Your vehicle”. It is orientation, not navigation: it has no links and is not a Tab stop.

Package
@kvirn-ui/react
Testing
Automated. Core 0 of 2, Release 0 of 3

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

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

Step 2 of 5: Your vehicle

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.

Step 1 of 3: Your details

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.

Who is the vehicle registered to?

(optional)

Step 2 of 5: Your vehicle

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

Props in this example:

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> with as (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 ?".

PartElement / roleARIANotes
Stepper<p> → implicit paragraph, no explicit rolenoneclass="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
Stepperasthe chosen element's ownOne 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
Stepperneverno role, tabindexNo 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
useStepperthe same, for your own markuptext, element, rootPropstext 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, label and legend, 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 the h1 or the legend, before the description and the control.
  • Text. stepper.status without a name, stepper.statusWithName with one. Each locale owns its word order and punctuation; numbers follow the language's number format. A blank name counts as none.
  • Dev warnings (once): a current or total that is not a positive whole number, or a current above total; a Stepper rendered inside an h1–h6 or role="heading", label, legend, summary, button, a or caption.

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, with useLocale().localeProps on 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 (useRouteFocus to the h1; 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
Stepperp (default), divA 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 actionRead aloudPolitenessTest
A question page read top to bottomheading, Which vehicle is the permit for?, level 1 → paragraph → Step 2 of 5: Your vehiclenonestepper.test.tsx › is the reading stop right after the heading
Without a name, or a blank nameparagraph → Step 2 of 5, no colonnonestepper.test.tsx › reads without a name and with a blank name as the position alone
Label or legend as the headingthe Stepper after the h1 or the legend, before the control: not read in that statenonenone (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.

PropTypeDefaultDescription
currentnumberRequiredThe step the user is on: a positive whole number, at most total.
totalnumberRequiredHow many steps there are: a positive whole number. Count sections, so an answer that adds a page never changes it.
namestring–The section’s name, in plain words: “Your vehicle”. A blank name counts as none.
messagesPartial<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.
refRef<HTMLElement>–Reaches the element, whichever it is.
Class or attributeValuesMeaning
kv-stepperalwaysThe part class. The default theme styles it. Stepper has no state, so no data-*.

useStepper

Options

PropTypeDefaultDescription
currentnumberRequiredThe step the user is on: a positive whole number, at most total.
totalnumberRequiredHow many steps there are: a positive whole number. Count sections, so an answer that adds a page never changes it.
namestring–The section’s name, in plain words: “Your vehicle”. A blank name counts as none.
messagesPartial<KvirnMessages['stepper']>–Replaces stepper.status and stepper.statusWithName for this instance.

Result

PropTypeDefaultDescription
textstring–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.
rootPropsStepperPartProps–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.

LanguageDefault text
SvenskaSteg 2 av 5
SuomiVaihe 2/5
Norsk bokmålSteg 2 av 5
Norsk nynorskSteg 2 av 5
EnglishStep 2 of 5

stepper.statusWithName

The text with the section’s name.

LanguageDefault text
SvenskaSteg 2 av 5: Your vehicle
SuomiVaihe 2/5: Your vehicle
Norsk bokmålSteg 2 av 5: Your vehicle
Norsk nynorskSteg 2 av 5: Your vehicle
EnglishStep 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 + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespassn/apassstepper.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apassstepper.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)passn/apassstepper.test.tsx › keyboard › Tab passes over it
Focus order and managementn/an/an/anothing focusable: the component never takes or moves focus
Display modes (forced colours, 320px reflow, text spacing, reduced motion)passn/apassthe four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI
Core (required for beta)
NVDA + Chrome + Windowspendingpendingpending
VoiceOver + Safari + iOSpendingpendingpending
Release (before 1.0 and each minor)
JAWS + Chrome + Windowspendingpendingpending
TalkBack + Chrome + Androidpendingpendingpending
VoiceOver + Safari + macOSpendingpendingpending

What to check#

  • Read from the heading to the next item: you hear one paragraph, "Step 2 of 5: Your vehicle". Tab skips it.