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
valueonly 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#
import { Button, Progress } from '@kvirn-ui/react'
import { useState } from 'react'
import { useProgressTexts } from './texts.ts'
export function DefaultProgress() {
const { texts } = useProgressTexts()
const [isWaiting, setIsWaiting] = useState(false)
return (
<div>
<Button onClick={() => setIsWaiting(!isWaiting)}>
{isWaiting ? texts.stop : texts.start}
</Button>
{isWaiting ? (
<Progress.Root label={texts.sending}>
<Progress.Indicator />
<Progress.Label />
</Progress.Root>
) : null}
</div>
)
}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).
import { Alert, Button, Progress } from '@kvirn-ui/react'
import { useEffect, useState } from 'react'
import { useProgressTexts } from './texts.ts'
export function BusyButton() {
const { texts } = useProgressTexts()
const [state, setState] = useState<'idle' | 'sending' | 'failed'>('idle')
useEffect(() => {
if (state !== 'sending') {
return
}
const timer = setTimeout(() => setState('failed'), 4000)
return () => clearTimeout(timer)
}, [state])
return (
<div>
<div className="kv-button-group">
<Button
className="kv-button--primary"
busy={state === 'sending'}
onClick={() => setState('sending')}
>
{state === 'failed' ? texts.retry : texts.send}
</Button>
{state === 'sending' ? (
<Progress.Root label={texts.sending}>
<Progress.Label />
</Progress.Root>
) : null}
</div>
{state === 'failed' ? (
<Alert.Danger announce="polite">
<Alert.Title as="p">{texts.failed}</Alert.Title>
</Alert.Danger>
) : null}
</div>
)
}Props in this example:
labelon Progress.Root
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.
import { Alert, Button, Progress } from '@kvirn-ui/react'
import { useEffect, useState } from 'react'
import { useProgressTexts } from './texts.ts'
export function KnownValue() {
const { texts } = useProgressTexts()
const [value, setValue] = useState<number | undefined>(undefined)
const isDone = value !== undefined && value >= 100
useEffect(() => {
if (value === undefined || value >= 100) {
return
}
const timer = setTimeout(() => setValue(value + 5), 250)
return () => clearTimeout(timer)
}, [value])
return (
<div>
<Button onClick={() => setValue(0)}>{texts.export}</Button>
{value === undefined || isDone ? null : (
<Progress.Root label={texts.exporting} value={value}>
<Progress.Label />
<Progress.Bar />
</Progress.Root>
)}
{isDone ? (
<Alert.Success announce="polite">
<Alert.Title as="p">{texts.exported}</Alert.Title>
</Alert.Success>
) : null}
</div>
)
}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.
import { Button, Progress } from '@kvirn-ui/react'
import { useState } from 'react'
import { useProgressTexts } from './texts.ts'
export function SlowWait() {
const { texts } = useProgressTexts()
const [isWaiting, setIsWaiting] = useState(false)
return (
<div>
<Button onClick={() => setIsWaiting(!isWaiting)}>
{isWaiting ? texts.stop : texts.start}
</Button>
{isWaiting ? (
<Progress.Root
label={texts.slowSending}
delayMilliseconds={500}
slowAfterMilliseconds={4000}
>
<Progress.Indicator />
<Progress.Label />
</Progress.Root>
) : null}
</div>
)
}Props in this example:
slowAfterMillisecondson Progress.RootdelayMillisecondson Progress.Root
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.
import { Button, useFormat, useProgress } from '@kvirn-ui/react'
import { useEffect, useState } from 'react'
import { useProgressTexts } from './texts.ts'
function Waiting({ label, value }: { label: string; value: number }) {
const progress = useProgress({ label, value })
const format = useFormat()
if (!progress.isShown || progress.barProps === undefined) {
return null
}
return (
<div {...progress.rootProps}>
<p {...progress.labelProps}>
<span id={progress.labelId}>{progress.label}</span>{' '}
<span>{format.number(value / 100, { style: 'percent' })}</span>
{progress.isSlow ? <span> {progress.slowText}</span> : null}
</p>
<progress {...progress.barProps} />
</div>
)
}
export function OwnMarkup() {
const { texts } = useProgressTexts()
const [value, setValue] = useState<number | undefined>(undefined)
useEffect(() => {
if (value === undefined || value >= 100) {
return
}
const timer = setTimeout(() => setValue(value + 5), 250)
return () => clearTimeout(timer)
}, [value])
return (
<div>
<Button onClick={() => setValue(0)}>{texts.export}</Button>
{value === undefined || value >= 100 ? null : (
<Waiting label={texts.exporting} value={value} />
)}
</div>
)
}Props in this example:
valueon useProgress (options)isShownon useProgress (result)labelIdon useProgress (result)barPropson useProgress (result)
Accessibility#
What it does for you#
- APG pattern: none. A progress bar is not a widget and has no keys. The native form,
<progress>(implicitprogressbarrole), 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.
| Part | Element / role | ARIA / state | Notes |
|---|---|---|---|
| Progress.Root | <div>, no role | data-state="busy" or "slow", data-determinate with a value. Never aria-live, never aria-busy | Class 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 region | Class 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 role | aria-hidden="true", not focusable | Class 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> → progressbar | value, 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 |
useProgress | the same, for your own markup | isShown, 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-labelledbythe span). The slow sentence and the percent are not in the name. Without alabelthe messageprogress.loadingis used and a development warning asks for a specific one. - No state of its own for the page. No
aria-busyfrom Progress:aria-busybelongs 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.Indicatorrenders 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 noKvirnProviderwhile 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.Dangernear the button withannounce="polite", and turnbusyoff. 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. Passannounce={false}only when focus already reads the state or another part announces it (a Table withisLoading). - 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: reduceand 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 |
|---|---|---|
| Label | p (default), div, span | Plain 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, Bar | none | A <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).
| When | What it says | Message key | Politeness |
|---|---|---|---|
Shown after the delay (unless announce={false}) | label progress.loading | Polite | |
| Becomes slow (10 s) | progress.slow | Polite |
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.
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | the message progress.loading | What 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. |
value | number | – | How far along, when you know it. The bar renders only with a number; an unknown wait has the label alone. |
max | number | 100 | The value that means done. |
delayMilliseconds | number | 0 | How 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. |
slowAfterMilliseconds | number | false | 10000 | When, counted from mounting, the slow sentence is added. false never adds it. |
announce | boolean | true | Announces 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. |
messages | Partial<KvirnMessages['progress']> | – | Per-instance override of the loading, slow and value texts. |
ref | Ref<HTMLDivElement> | – | Reaches the <div>. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-progress | always | The part class. The default theme styles it. |
data-state | busy | slow | slow once the wait passed slowAfterMilliseconds. |
data-determinate | present with a value | The 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.
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<HTMLSpanElement> | – | Reaches the <span>. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-spinner | always | The spinner class. kv-spinner--sm and kv-spinner--lg change its size. The theme shows a still shape under reduced motion. |
aria-hidden | true | It 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.
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'p' | 'div' | 'span' | 'p' | Changes the element: span fits beside a busy button. It is plain text, never a heading. |
children | ReactNode | the Root’s label | Another text than the Root’s label. It names the bar, so keep it the same words. |
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-progress-label | always | The part class. |
kv-progress-percent | on a span, with a value | The visible percent after the label text. It is text, never announced. |
kv-progress-slow | on a span, once slow | The 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.
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<HTMLProgressElement> | – | Reaches the <progress>. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-progress-bar | always | The part class. |
aria-labelledby | the label text’s id | Names the bar by the label text only, not by the percent or the slow sentence. |
aria-valuetext | the message progress.valueText | For example “Exporting cases, 45%”. |
useProgress
Options
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | the message progress.loading | What 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. |
value | number | – | How far along, when you know it. The bar renders only with a number; an unknown wait has the label alone. |
max | number | 100 | The value that means done. |
delayMilliseconds | number | 0 | How 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. |
slowAfterMilliseconds | number | false | 10000 | When, counted from mounting, the slow sentence is added. false never adds it. |
announce | boolean | true | Announces 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. |
messages | Partial<KvirnMessages['progress']> | – | Per-instance override of the loading, slow and value texts. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
isShown | boolean | – | false while the wait is still inside the show delay: render nothing. |
isSlow | boolean | – | true once the wait passed the slow limit. |
labelId | string | – | The id for the element that holds the label text, which names the bar. |
label | string | – | The label, or the message progress.loading. |
slowText | string | – | The message progress.slow. Show it after the label when isSlow. |
percent | number | undefined | – | The value as a whole percent, 0 to 100. undefined without a value. |
rootProps | ProgressRootPartProps | – | Spread on the Root’s element: the class, data-state and, with a value, data-determinate. |
labelProps | ProgressLabelPartProps | – | Spread on the element around the label text. |
barProps | ProgressBarPartProps | 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.
| Language | Default text |
|---|---|
| Svenska | Laddar. |
| Suomi | Ladataan. |
| Norsk bokmål | Laster. |
| Norsk nynorsk | Lastar. |
| English | Loading. |
progress.slow
The sentence added after the label once the wait is slow, and announced once.
| Language | Default text |
|---|---|
| Svenska | Det tar längre tid än vanligt. Låt den här sidan vara öppen. |
| Suomi | Tämä kestää tavallista kauemmin. Pidä tämä sivu auki. |
| Norsk bokmål | Dette tar lengre tid enn vanlig. La denne siden stå åpen. |
| Norsk nynorsk | Dette tek lengre tid enn vanleg. La denne sida stå open. |
| English | This is taking longer than usual. Keep this page open. |
progress.valueText
The bar’s value text, for example “Exporting cases, 45%”.
| Language | Default text |
|---|---|
| Svenska | Exporting cases, 45 % |
| Suomi | Exporting cases, 45 % |
| Norsk bokmål | Exporting cases, 45 % |
| Norsk nynorsk | Exporting cases, 45 % |
| English | Exporting cases, 45% |
Known issues#
aria-valuetextrepeats the label. The messageprogress.valueTextis{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-valuetextis built from the Root'slabel, not fromProgress.Labelchildren. Keep the same words in both, or the bar's name and its value text differ.- A
labelthat changes while waiting is not announced again. Remount the Root with akeywhen 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
delayMillisecondsfor 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 + 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 | progress.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | progress.test.tsx › shows the label as plain text with no role; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | progress.test.tsx › keyboard › Tab passes over it: it has no focusable part |
| 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#
- Start a send: the label is spoken once and politely, focus stays on the busy button, and nothing is spoken when the percent changes.