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.

Progress

Says that something is working and, when it is known, how far along. Shows that something the user started is still working, and how far along it is when you know. A screen reader announces it once, and a sentence is added when the wait is slow.

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

When to use it#

  • Use it for a wait the user started: a send, a filter, a route change. Put it where the result will appear, or right after the busy button.
  • Name the thing and the action, and end with a full stop: “Sending your application.”, not “Loading…” or “Please wait”.
  • Give it a value only when you know how far along it is. An unknown wait has the label alone, with a spinner if you like.
  • It shows at once. For a wait that is often quick, set delayMilliseconds, so a short wait never flashes on the screen.
  • Not for a message about something that happened: that is an Alert. A Table and a FileUpload keep their own loading text.

Example#

Use cases#

A busy button while sending

The pattern for a long action. The Button is busy, so a second press is blocked and focus stays on it. The Progress sits right after it and has no spinner of its own, because the busy button already has one. On failure the Progress goes, an Alert takes its place and busy turns off. The screen reader says the label once, politely (see Announcements).

Props in this example:

Warning: Don't forget

Announcements need a KvirnProvider around your app. Without one the Progress is shown but not announced, and a development warning says so.

A wait with a known value

When you know how far along it is, pass a value. The browser’s own progress bar appears, named by the label, and the percent is shown as text after it. The library never announces the percent, so a screen reader is not interrupted at every step. When the wait ends the Progress disappears without a word, so show the result, here an Alert.

Props in this example:

Warning: Don't forget

Give the Root a label that says what is happening. Without one the text is only “Loading.” (4.1.2 Name, Role, Value). If you also pass text to the Label, use the same words: the bar’s value text is built from the Root’s label.

A wait that takes longer than expected

After ten seconds by default, a sentence is added saying that the wait is taking longer and to keep the page open, and it is announced once. Here the limit is four seconds, and a wait shorter than half a second is never shown. Set another limit, or false to never add the sentence.

Props in this example:

With your own elements

When the markup is yours, spread the props of the hook on your elements and render nothing while isShown is false. Put labelId on the label text and spread barProps on a <progress>, so the label names the bar. The hook still announces the wait for you.

Props in this example:

Accessibility#

What it does for you#

  • APG pattern: none. A progress bar is not a widget and has no keys. The native form, <progress> (implicit progressbar role), is used only when the value is known.
  • Deviations: none.
  • Native elements used: <div>, <p> and <span> for the text, <progress> for a known value.

Progress says that something is working and, when known, how far along. It is for a wait the user started (a send, a filter, a route), placed where the result will appear or beside the busy button. It renders at once; delayMilliseconds holds it back for a wait that is often quick. Table, Combobox and FileUpload keep their own loading text.

PartElement / roleARIA / stateNotes
Progress.Root<div>, no roledata-state="busy" or "slow", data-determinate with a value. Never aria-live, never aria-busyClass kv-progress. Not rendered before delayMilliseconds (default 0). Props: label, value, max, delayMilliseconds, slowAfterMilliseconds, announce, messages
Progress.Label<p> holding <span id>none. Never a live regionClass kv-progress-label. The <span id> is the label text only; the percent (kv-progress-percent) and the slow sentence (kv-progress-slow) are separate spans after it
Progress.Indicator<span>, no rolearia-hidden="true", not focusableClass kv-spinner (kv-spinner--sm, --lg), a direct child of the Root before the label. Renders only without a value: one indicator per wait. Loops while the wait lasts and shows its still rest shape under reduced motion; the text carries the wait
Progress.Bar<progress> → progressbarvalue, max (100), aria-labelledby the label span, aria-valuetext (progress.valueText: Exporting cases, 45%)Class kv-progress-bar. Renders only with a numeric value: an unknown wait has no bar and no progressbar role
useProgressthe same, for your own markupisShown, isSlow, labelId, label, slowText, percent, rootProps, labelProps, barProps (undefined without value)Render nothing while isShown is false

Rules the tests prove:

  • Show delay. Nothing is rendered or said inside delayMilliseconds. A wait that ends inside it is never shown or announced.
  • Name. The bar is named by the label text only (aria-labelledby the span). The slow sentence and the percent are not in the name. Without a label the message progress.loading is used and a development warning asks for a specific one.
  • No state of its own for the page. No aria-busy from Progress: aria-busy belongs on the element whose content is replaced, while it is replaced (Table does this).
  • The percent is text. The visible percent follows the label, and the bar's value says it. It is never announced.
  • One indicator per wait. Progress.Indicator renders only for an unknown value; a known value has the <progress> and no spinner. A <progress> is never rendered without a value.
  • Development warnings (once each): a Progress with no label, a Label, Bar or Indicator outside a Root, and no KvirnProvider while announcing.

What you need to do#

  • Name the thing and the action, and end with a full stop: "Sending your application.", never "Loading…" or "Please wait". No ellipsis, no tech words.
  • Place it where the result will appear, or directly after the busy Button in the same row. Never a Toast or a modal for a wait.
  • Pair a busy action with <Button busy> so a second press is blocked and focus stays.
  • On failure, remove the Progress and show an Alert.Danger near the button with announce="polite", and turn busy off. Success speaks through the result's own announcement or a focus move.
  • Offer Cancel as a separate button, never inside Progress.
  • Wrap the app in KvirnProvider: the wait is announced through it. Without one nothing is announced and a development warning says why. Pass announce={false} only when focus already reads the state or another part announces it (a Table with isLoading).
  • Never put a Progress inside an Alert's tinted background, or on a page-wide overlay that hides the user's answers.
  • 2.2.2 Pause, Stop, Hide (A). The indicators (spinner, bar sheen, busy Button, job Toast, FileUpload track, Table busy sweep) move for as long as the wait lasts, which can be more than 5 s. The theme honours prefers-reduced-motion: reduce and shows a still shape, but that setting alone is not a control on the page. An indicator that can keep moving for more than 5 seconds alongside other content needs a visible control on the page that stops or hides it. An indicator that is the only content during a wait where nothing else can be done is exempt. The library ships no such control, so the app offers its own and applies the CSS that stops the indicators. The Theming page of the Foundation section explains moving indicators and WCAG 2.2.2. The text, the percent and the 10 s slow sentence carry the wait.

Warning: Don't forget

An indicator that keeps moving for more than 5 seconds next to other content needs a visible control on the page that stops or hides it (2.2.2 Pause, Stop, Hide, level A). The reduced motion setting alone is not that control, and an indicator that is the only content during a wait where nothing else can be done needs none. Read Moving indicators and WCAG 2.2.2.

Visual and modes#

  • Focus indicator: none (nothing is focusable).
  • Colour: the label and the percent use the full-strength text colour, never the muted one. The percent is text too, so the state never depends on colour (1.4.1 Use of Color, A). The bar's edge has at least 3:1 contrast against its background (1.4.11 Non-text Contrast, AA).
  • Forced colours: the text and the bar's edge use the system's text colour, the track uses the system's background, and the value uses the system's highlight colour.
  • Reduced motion: the spinner shows its still rest shape. The known-value bar shows a plain gradient fill with no moving sheen, and its fill changes smoothly only when motion is allowed.
  • Right-to-left: the native bar fills from the inline start of the page direction, and the label wraps. Spacing uses logical properties throughout.

Focus management#

  • Initial focus: not moved.
  • Trap: no.
  • Restore to: not applicable. Progress never moves focus, on show, slow or unmount.
  • Never obscured by: Progress is in the flow, never an overlay.

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
Labelp (default), div, spanPlain text with the label span inside. span fits beside a busy button. No heading: it names the bar, it is not part of the outline. A value outside the list is a type error and, in JavaScript, warns once in development and renders the default element.
Root, Indicator, BarnoneA <div>, a decorative <span> and a native <progress> (4.1.2 Name, Role, Value (A))

WCAG success criteria#

  • 1.3.1 Info and Relationships (A) and 4.1.2 Name, Role, Value (A): a known value is a native <progress>, named by the label.
  • 4.1.3 Status Messages (AA): the wait is announced through the Announcer once when shown and once when slow.
  • 1.4.1 Use of Color (A) and 1.4.11 Non-text Contrast (AA): the label and the percent carry the state, and the bar's edge has at least 3:1 contrast.
  • 1.4.10 Reflow (AA) and 1.4.12 Text Spacing (AA): the label wraps and has no fixed height.
  • 2.2.2 Pause, Stop, Hide (A): every indicator animation (the spinner, the known-value bar's sheen, the busy Button and Toast spinners, the FileUpload track, the Table busy sweep) loops while the wait lasts and shows the still rest shape under prefers-reduced-motion: reduce. The library has no stop control. Where an indicator can keep moving for more than 5 seconds alongside other content, the app offers one (see What you need to do).
  • 2.4.3 Focus Order (A): focus is never moved.

Keyboard#

Progress has no keys of its own. What you put in it keeps its own keys.

Announcements#

Progress tells screen reader users about these changes without moving focus. Each message waits until the screen reader is quiet (polite) or interrupts it (assertive).

WhenWhat it saysMessage keyPoliteness
Shown after the delay (unless announce={false})label progress.loadingPolite
Becomes slow (10 s)progress.slowPolite

The text in all five languages

Change the text#

For your whole app, pass messages to KvirnProvider. For one Progress, pass its messages prop.

<KvirnProvider messages={{ progress: { label: '…' } }}>

Warning: Don't forget

Announcements need a KvirnProvider around your app, outside any <form>, or an Announcer of your own. Without one nothing is announced, and a development warning says so.

API reference#

import { Progress, useProgress } from '@kvirn-ui/react'

Progress.Root

Renders <div> with no role. It renders nothing until the show delay has passed, and it takes every attribute of a <div> and passes ref to it. Also exported as ProgressRoot. The default theme is described on Theming.

PropTypeDefaultDescription
labelstringthe message progress.loadingWhat is happening, as a short sentence that ends with a full stop. It names the bar and is announced once. Without it a development warning asks for a specific one.
valuenumber–How far along, when you know it. The bar renders only with a number; an unknown wait has the label alone.
maxnumber100The value that means done.
delayMillisecondsnumber0How long a wait stays hidden before it is shown. 0 shows it at once. Set a delay for a wait that is often quick, so it never flashes. A wait that ends inside the delay is never shown or announced.
slowAfterMillisecondsnumber | false10000When, counted from mounting, the slow sentence is added. false never adds it.
announcebooleantrueAnnounces the label once when it is shown and the slow sentence once when it becomes slow. Set false when focus already reads the state or another part announces it. The percent is never announced.
messagesPartial<KvirnMessages['progress']>–Per-instance override of the loading, slow and value texts.
refRef<HTMLDivElement>–Reaches the <div>.
Class or attributeValuesMeaning
kv-progressalwaysThe part class. The default theme styles it.
data-statebusy | slowslow once the wait passed slowAfterMilliseconds.
data-determinatepresent with a valueThe wait has a known value, so the Bar renders.

Progress.Indicator

Renders A decorative <span> with no role and aria-hidden, a direct child of the Root before the Label. It renders nothing when the Root has a value. Also exported as ProgressIndicator.

PropTypeDefaultDescription
refRef<HTMLSpanElement>–Reaches the <span>.
Class or attributeValuesMeaning
kv-spinneralwaysThe spinner class. kv-spinner--sm and kv-spinner--lg change its size. The theme shows a still shape under reduced motion.
aria-hiddentrueIt is decoration; the text carries the wait.

Progress.Label

Renders <p> with plain text: the label, then the percent when the value is known, then the slow sentence. Only the label names the bar. It is never a live region. Also exported as ProgressLabel.

PropTypeDefaultDescription
as'p' | 'div' | 'span''p'Changes the element: span fits beside a busy button. It is plain text, never a heading.
childrenReactNodethe Root’s labelAnother text than the Root’s label. It names the bar, so keep it the same words.
refRef<HTMLElement>–Reaches the element, whichever it is.
Class or attributeValuesMeaning
kv-progress-labelalwaysThe part class.
kv-progress-percenton a span, with a valueThe visible percent after the label text. It is text, never announced.
kv-progress-slowon a span, once slowThe slow sentence after the label text. It is not part of the bar’s name.

Progress.Bar

Renders A native <progress> with the role progressbar. It renders only when the Root has a numeric value. It takes every attribute of a <progress> except value, max and aria-labelledby, and passes ref to it. Also exported as ProgressBar.

PropTypeDefaultDescription
refRef<HTMLProgressElement>–Reaches the <progress>.
Class or attributeValuesMeaning
kv-progress-baralwaysThe part class.
aria-labelledbythe label text’s idNames the bar by the label text only, not by the percent or the slow sentence.
aria-valuetextthe message progress.valueTextFor example “Exporting cases, 45%”.

useProgress

Options

PropTypeDefaultDescription
labelstringthe message progress.loadingWhat is happening, as a short sentence that ends with a full stop. It names the bar and is announced once. Without it a development warning asks for a specific one.
valuenumber–How far along, when you know it. The bar renders only with a number; an unknown wait has the label alone.
maxnumber100The value that means done.
delayMillisecondsnumber0How long a wait stays hidden before it is shown. 0 shows it at once. Set a delay for a wait that is often quick, so it never flashes. A wait that ends inside the delay is never shown or announced.
slowAfterMillisecondsnumber | false10000When, counted from mounting, the slow sentence is added. false never adds it.
announcebooleantrueAnnounces the label once when it is shown and the slow sentence once when it becomes slow. Set false when focus already reads the state or another part announces it. The percent is never announced.
messagesPartial<KvirnMessages['progress']>–Per-instance override of the loading, slow and value texts.

Result

PropTypeDefaultDescription
isShownboolean–false while the wait is still inside the show delay: render nothing.
isSlowboolean–true once the wait passed the slow limit.
labelIdstring–The id for the element that holds the label text, which names the bar.
labelstring–The label, or the message progress.loading.
slowTextstring–The message progress.slow. Show it after the label when isSlow.
percentnumber | undefined–The value as a whole percent, 0 to 100. undefined without a value.
rootPropsProgressRootPartProps–Spread on the Root’s element: the class, data-state and, with a value, data-determinate.
labelPropsProgressLabelPartProps–Spread on the element around the label text.
barPropsProgressBarPartProps | undefined–Spread on a <progress>. undefined without a numeric value: an unknown wait has no bar.

Strings

These are the default texts in @kvirn-ui/i18n.

For your whole app, pass messages to KvirnProvider. For one Progress, pass its messages prop.

progress.loading

The label when you pass none. A development warning asks for a specific one.

LanguageDefault text
SvenskaLaddar.
SuomiLadataan.
Norsk bokmålLaster.
Norsk nynorskLastar.
EnglishLoading.

progress.slow

The sentence added after the label once the wait is slow, and announced once.

LanguageDefault text
SvenskaDet tar längre tid än vanligt. Låt den här sidan vara öppen.
SuomiTämä kestää tavallista kauemmin. Pidä tämä sivu auki.
Norsk bokmålDette tar lengre tid enn vanlig. La denne siden stå åpen.
Norsk nynorskDette tek lengre tid enn vanleg. La denne sida stå open.
EnglishThis is taking longer than usual. Keep this page open.

progress.valueText

The bar’s value text, for example “Exporting cases, 45%”.

LanguageDefault text
SvenskaExporting cases, 45 %
SuomiExporting cases, 45 %
Norsk bokmålExporting cases, 45 %
Norsk nynorskExporting cases, 45 %
EnglishExporting cases, 45%

Known issues#

  • aria-valuetext repeats the label. The message progress.valueText is {label}, {percent}, so a screen reader may read the label twice. If it reads badly with your screen reader, drop the label from the value text and let the native percent speak.
  • aria-valuetext is built from the Root's label, not from Progress.Label children. Keep the same words in both, or the bar's name and its value text differ.
  • A label that changes while waiting is not announced again. Remount the Root with a key when the wait is a new one.
  • Unmounting within 100 ms after the Announcer was given a message may still speak it: the Announcer fills its region 100 ms after the call. With the default delay of 0 this is every wait shorter than about 100 ms: the label is spoken after the Progress has gone. Set delayMilliseconds for a wait that is usually quick.
  • A slow limit less than 100 ms after the label replaces the label before it is spoken; the slow sentence is still announced.

Information: Did you know?

If an issue here affects your service, list it in your accessibility statement with its workaround.

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/apassprogress.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apassprogress.test.tsx › shows the label as plain text with no role; expectNoA11yViolations
Keyboard contract rows (Vitest browser)passn/apassprogress.test.tsx › keyboard › Tab passes over it: it has no focusable part
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#

  • Start a send: the label is spoken once and politely, focus stays on the busy button, and nothing is spoken when the percent changes.