When to use it#
- Use it after a failed submit, when people may not see every error at once: a form with several fields, or a long one.
- Show it at the top of the main content, above the form, and only while there are errors. Pass the submit count as
focusKey, so a second failed submit moves focus again. - Write each link as the field’s own error, with what to do: “Enter your email address”, not “Invalid”. Keep the error under the field too.
- Not for a message that isn’t about a form: use an Alert. Don’t update it while the user types.
Example#
import { Button, ErrorSummary, Field, Stack, TextInput } from '@kvirn-ui/react'
import { useId, useState } from 'react'
import { useErrorSummaryTexts } from './texts.ts'
export function DefaultErrorSummary() {
const { texts } = useErrorSummaryTexts()
const idPrefix = useId()
const [isShown, setIsShown] = useState(false)
const emailId = `${idPrefix}-email`
const phoneId = `${idPrefix}-phone`
return (
<Stack className="kv-stack--gap-8">
<Button onClick={() => setIsShown(true)}>{texts.showSummary}</Button>
{isShown ? (
<ErrorSummary.Root>
<ErrorSummary.Title />
<ErrorSummary.List>
<ErrorSummary.Item>
<ErrorSummary.Link controlId={emailId}>{texts.emailError}</ErrorSummary.Link>
</ErrorSummary.Item>
<ErrorSummary.Item>
<ErrorSummary.Link controlId={phoneId}>{texts.phoneError}</ErrorSummary.Link>
</ErrorSummary.Item>
</ErrorSummary.List>
</ErrorSummary.Root>
) : null}
<Field.Root controlId={emailId} required invalid={isShown}>
<Field.Label>{texts.email}</Field.Label>
<TextInput type="email" autoComplete="email" />
<Field.ErrorMessage>{texts.emailError}</Field.ErrorMessage>
</Field.Root>
<Field.Root controlId={phoneId} required invalid={isShown}>
<Field.Label>{texts.phone}</Field.Label>
<TextInput type="tel" autoComplete="tel" />
<Field.ErrorMessage>{texts.phoneError}</Field.ErrorMessage>
</Field.Root>
</Stack>
)
}Use cases#
A form that fails to send
On submit, check the answers, mark the fields invalid and show the summary. Each link and its field’s error say the same words, and each link points at the id you gave the field with controlId.
import { Button, ErrorSummary, Field, Stack, TextInput } from '@kvirn-ui/react'
import { useId, useState } from 'react'
import { useErrorSummaryTexts } from './texts.ts'
export function FailedSubmit() {
const { texts } = useErrorSummaryTexts()
const idPrefix = useId()
const emailId = `${idPrefix}-email`
const phoneId = `${idPrefix}-phone`
const [submitCount, setSubmitCount] = useState(0)
const [errors, setErrors] = useState({ email: false, phone: false })
const [isSent, setIsSent] = useState(false)
const hasErrors = errors.email || errors.phone
return (
<Stack className="kv-stack--gap-8">
{hasErrors ? (
<ErrorSummary.Root focusKey={submitCount}>
<ErrorSummary.Title />
<ErrorSummary.List>
{errors.email ? (
<ErrorSummary.Item>
<ErrorSummary.Link controlId={emailId}>{texts.emailError}</ErrorSummary.Link>
</ErrorSummary.Item>
) : null}
{errors.phone ? (
<ErrorSummary.Item>
<ErrorSummary.Link controlId={phoneId}>{texts.phoneError}</ErrorSummary.Link>
</ErrorSummary.Item>
) : null}
</ErrorSummary.List>
</ErrorSummary.Root>
) : null}
<form
noValidate
onSubmit={(event) => {
event.preventDefault()
const data = new FormData(event.currentTarget)
const next = { email: data.get('email') === '', phone: data.get('phone') === '' }
setErrors(next)
setSubmitCount((count) => count + 1)
setIsSent(!next.email && !next.phone)
}}
>
<Field.Root controlId={emailId} required invalid={errors.email}>
<Field.Label>{texts.email}</Field.Label>
<TextInput name="email" type="email" autoComplete="email" />
<Field.ErrorMessage>{texts.emailError}</Field.ErrorMessage>
</Field.Root>
<Field.Root controlId={phoneId} required invalid={errors.phone}>
<Field.Label>{texts.phone}</Field.Label>
<TextInput name="phone" type="tel" autoComplete="tel" />
<Field.ErrorMessage>{texts.phoneError}</Field.ErrorMessage>
</Field.Root>
<Button type="submit" className="kv-button--primary">
{texts.send}
</Button>
</form>
<output>{isSent ? texts.sent : null}</output>
</Stack>
)
}Props in this example:
Warning: Don't forget
Set controlId on every Field.Root a link points at, and keep the Field.ErrorMessage under the control (3.3.1 Error Identification). A link to an id that isn’t on the page goes nowhere, and a development warning says so.
An error on a group of fields
When the question is the group, such as first and last name, the error belongs to the Fieldset. Link to the first box that is wrong: the link focuses it and scrolls its label into view. A group of radio buttons links to its first option in the same way.
import { Button, ErrorSummary, Field, Fieldset, Stack, TextInput } from '@kvirn-ui/react'
import { useId, useState } from 'react'
import { useErrorSummaryTexts } from './texts.ts'
export function GroupError() {
const { texts } = useErrorSummaryTexts()
const idPrefix = useId()
const firstNameId = `${idPrefix}-first-name`
const lastNameId = `${idPrefix}-last-name`
const [submitCount, setSubmitCount] = useState(0)
// The id of the first box left empty: the summary links to it.
const [firstEmptyId, setFirstEmptyId] = useState<string | undefined>(undefined)
return (
<Stack className="kv-stack--gap-8">
{firstEmptyId === undefined ? null : (
<ErrorSummary.Root focusKey={submitCount}>
<ErrorSummary.Title />
<ErrorSummary.List>
<ErrorSummary.Item>
<ErrorSummary.Link controlId={firstEmptyId}>{texts.nameError}</ErrorSummary.Link>
</ErrorSummary.Item>
</ErrorSummary.List>
</ErrorSummary.Root>
)}
<Stack
className="kv-stack--gap-8"
as="form"
noValidate
onSubmit={(event) => {
event.preventDefault()
const data = new FormData(event.currentTarget)
setFirstEmptyId(
data.get('firstName') === ''
? firstNameId
: data.get('lastName') === ''
? lastNameId
: undefined,
)
setSubmitCount((count) => count + 1)
}}
>
<Fieldset.Root group required invalid={firstEmptyId !== undefined}>
<Fieldset.Legend>{texts.nameQuestion}</Fieldset.Legend>
<Field.Root controlId={firstNameId} required>
<Field.Label>{texts.firstName}</Field.Label>
<TextInput name="firstName" autoComplete="given-name" />
</Field.Root>
<Field.Root controlId={lastNameId} required>
<Field.Label>{texts.lastName}</Field.Label>
<TextInput name="lastName" autoComplete="family-name" />
</Field.Root>
<Fieldset.ErrorMessage>{texts.nameError}</Fieldset.ErrorMessage>
</Fieldset.Root>
<Button type="submit" className="kv-button--primary">
{texts.send}
</Button>
</Stack>
</Stack>
)
}Props in this example:
controlIdon ErrorSummary.Link
A choice and a confirmation that were left out
Most forms mix text fields with options and a confirmation. A group of radio buttons links to its first option, and a checkbox to the box itself. Set controlId on the first RadioGroup.Option and on the checkbox’s Field.Root, and link to those ids.
import { Button, Checkbox, ErrorSummary, Field, RadioGroup, Stack } from '@kvirn-ui/react'
import { useId, useState } from 'react'
import { useErrorSummaryTexts } from './texts.ts'
export function MixedControls() {
const { texts } = useErrorSummaryTexts()
const idPrefix = useId()
// A group of options is linked by the id of its first option.
const firstVehicleId = `${idPrefix}-car`
const confirmId = `${idPrefix}-confirm`
const [submitCount, setSubmitCount] = useState(0)
const [errors, setErrors] = useState({ vehicle: false, confirm: false })
const [isSent, setIsSent] = useState(false)
const hasErrors = errors.vehicle || errors.confirm
return (
<Stack className="kv-stack--gap-8">
{hasErrors ? (
<ErrorSummary.Root focusKey={submitCount}>
{/* The docs page already has an h1, so the summary's title is an h4. On your pages the default is h2. */}
<ErrorSummary.Title as="h4" />
<ErrorSummary.List>
{errors.vehicle ? (
<ErrorSummary.Item>
<ErrorSummary.Link controlId={firstVehicleId}>
{texts.vehicleError}
</ErrorSummary.Link>
</ErrorSummary.Item>
) : null}
{errors.confirm ? (
<ErrorSummary.Item>
<ErrorSummary.Link controlId={confirmId}>{texts.confirmError}</ErrorSummary.Link>
</ErrorSummary.Item>
) : null}
</ErrorSummary.List>
</ErrorSummary.Root>
) : null}
<form
noValidate
onSubmit={(event) => {
event.preventDefault()
const data = new FormData(event.currentTarget)
const next = {
vehicle: data.get('vehicle') === null,
confirm: data.get('confirm') === null,
}
setErrors(next)
setSubmitCount((count) => count + 1)
setIsSent(!next.vehicle && !next.confirm)
}}
>
<Stack className="kv-stack--gap-8">
<RadioGroup.Root name="vehicle" required invalid={errors.vehicle}>
<RadioGroup.Legend>{texts.vehicleLegend}</RadioGroup.Legend>
<RadioGroup.Option controlId={firstVehicleId}>
<RadioGroup.Radio value="car" />
<Field.Label>{texts.car}</Field.Label>
</RadioGroup.Option>
<RadioGroup.Option>
<RadioGroup.Radio value="motorcycle" />
<Field.Label>{texts.motorcycle}</Field.Label>
</RadioGroup.Option>
<RadioGroup.ErrorMessage>{texts.vehicleError}</RadioGroup.ErrorMessage>
</RadioGroup.Root>
<Field.Root controlId={confirmId} required invalid={errors.confirm}>
<Checkbox name="confirm" value="yes" />
<Field.Label>{texts.confirm}</Field.Label>
<Field.ErrorMessage>{texts.confirmError}</Field.ErrorMessage>
</Field.Root>
<Button type="submit" className="kv-button--primary">
{texts.send}
</Button>
</Stack>
</form>
<output>{isSent ? texts.sent : null}</output>
</Stack>
)
}Props in this example:
A summary inside a dialog
A form in a Dialog needs the same summary. The dialog’s title is an h2, so give the summary’s Title as="h3" to keep the outline right. Clear the errors when the dialog closes, because its content stays in the page.
import { Button, Dialog, ErrorSummary, Field, TextInput } from '@kvirn-ui/react'
import { useId, useState } from 'react'
import { useErrorSummaryTexts } from './texts.ts'
export function InADialog() {
const { texts } = useErrorSummaryTexts()
const phoneId = `${useId()}-phone`
const [isOpen, setIsOpen] = useState(false)
const [submitCount, setSubmitCount] = useState(0)
const [hasError, setHasError] = useState(false)
const [savedPhone, setSavedPhone] = useState('')
return (
<>
<Dialog.Root
open={isOpen}
onOpenChange={(nextOpen) => {
setIsOpen(nextOpen)
// A closed dialog keeps its content, so clear the summary or it is there when it reopens.
setHasError(false)
}}
>
<Dialog.Trigger className="kv-button">{texts.changePhone}</Dialog.Trigger>
<Dialog.Popup>
<Dialog.Title>{texts.changePhone}</Dialog.Title>
<Dialog.Close />
<Dialog.Description>{texts.changePhoneText}</Dialog.Description>
{hasError ? (
<ErrorSummary.Root focusKey={submitCount}>
{/* The dialog's title is an h2, so the summary's is one level down. */}
<ErrorSummary.Title as="h3" />
<ErrorSummary.List>
<ErrorSummary.Item>
<ErrorSummary.Link controlId={phoneId}>{texts.phoneError}</ErrorSummary.Link>
</ErrorSummary.Item>
</ErrorSummary.List>
</ErrorSummary.Root>
) : null}
<form
noValidate
onSubmit={(event) => {
event.preventDefault()
const phone = new FormData(event.currentTarget).get('phone')
const isMissing = typeof phone !== 'string' || phone.trim() === ''
setHasError(isMissing)
setSubmitCount((count) => count + 1)
if (!isMissing) {
setSavedPhone(phone)
setIsOpen(false)
}
}}
>
<Dialog.Body>
<Field.Root controlId={phoneId} required invalid={hasError}>
<Field.Label>{texts.phone}</Field.Label>
<TextInput name="phone" type="tel" autoComplete="tel" />
<Field.ErrorMessage>{texts.phoneError}</Field.ErrorMessage>
</Field.Root>
</Dialog.Body>
<Dialog.Actions>
<Button type="submit" className="kv-button--primary">
{texts.saveNumber}
</Button>
<Dialog.Close className="kv-button">{texts.keepNumber}</Dialog.Close>
</Dialog.Actions>
</form>
</Dialog.Popup>
</Dialog.Root>
<output>{savedPhone === '' ? null : `${texts.numberSaved} ${savedPhone}`}</output>
</>
)
}Props in this example:
Say it in the page title too
The page title shows in the browser tab and is read first when a page loads. With prefixDocumentTitle the title starts with “Error:” while the summary is shown, and it is restored when you remove it.
Tab title now:
import { Button, ErrorSummary, Field, Stack, TextInput } from '@kvirn-ui/react'
import { useId, useState, useSyncExternalStore } from 'react'
import { useErrorSummaryTexts } from './texts.ts'
function subscribeToTitle(onChange: () => void) {
const observer = new MutationObserver(onChange)
observer.observe(document.head, { childList: true, subtree: true, characterData: true })
return () => observer.disconnect()
}
export function PageTitle() {
const { texts } = useErrorSummaryTexts()
const emailId = `${useId()}-email`
const [isShown, setIsShown] = useState(false)
const tabTitle = useSyncExternalStore(
subscribeToTitle,
() => document.title,
() => '',
)
return (
<Stack className="kv-stack--gap-8">
<Button onClick={() => setIsShown((shown) => !shown)}>
{isShown ? texts.hideSummary : texts.showSummary}
</Button>
{isShown ? (
<ErrorSummary.Root prefixDocumentTitle>
<ErrorSummary.Title />
<ErrorSummary.List>
<ErrorSummary.Item>
<ErrorSummary.Link controlId={emailId}>{texts.emailError}</ErrorSummary.Link>
</ErrorSummary.Item>
</ErrorSummary.List>
</ErrorSummary.Root>
) : null}
<Field.Root controlId={emailId} required invalid={isShown}>
<Field.Label>{texts.email}</Field.Label>
<TextInput type="email" autoComplete="email" />
<Field.ErrorMessage>{texts.emailError}</Field.ErrorMessage>
</Field.Root>
<p>
{texts.tabTitle} <q>{tabTitle}</q>
</p>
</Stack>
)
}Props in this example:
prefixDocumentTitleon ErrorSummary.Root
Information: Implement like this
If a router owns the title, leave the prop off and add the word from errorSummary.titlePrefix there.
Accessibility#
What it does for you#
- APG pattern: none. It applies the GOV.UK Error summary pattern and WCAG technique G139 (create a mechanism that allows users to jump to errors), with ARIA22's alternative (a focus move) in place of a live region.
- Deviations: none. It is not
role="alert": the focus move is the announcement. - Native elements used:
<ul>,<li>,<a href="#id">,<h2>(fromAlert.Title;aspicksh3toh6), and<ol>withason the List.
An Alert.Danger (see the Alert page) at the top of a form, shown after a failed submit, that lists every problem as a link to its field. Focus moves to it once, so the screen reader reads it and a keyboard user starts at the list.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Root | <div> (Alert.Danger) → group | aria-labelledby = the Title's id | tabindex="-1": focusable by script, not a Tab stop. No aria-live, no role="alert". Icon, status word and colour come from Alert.Danger |
| Title | <h2> (Alert.Title) → heading | id | Default text errorSummary.title. The status word ("Error:") comes first |
| List | <ul> → list | role="list" | One item per problem. role="list" is explicit: the theme draws no markers, and Safari would drop the list semantics without it |
| Item | <li> → listitem | none | |
| Link | <a href="#controlId"> → link | none | Its text is the field's error text, so it reads the same as the message under the field |
It announces nothing.
Information: Did you know?
The summary has no live region (a part of the page that a screen reader reads aloud when it changes) on purpose: the focus move is the announcement, and a live region on top of it would read it twice. A screen reader usually says only the name of a focused group, so listen with the screen readers your users have to confirm what they hear.
What you need to do#
- Render it only after a failed submit, at the top of
main, before the step caption and the form, and pass the submit count asfocusKeyso a second failed submit moves focus again. - Each Link's
controlIdis the id of the control (Field.Root controlId) or, for a group, of its first option. Its text is the same words as the field's error, including what to do (3.3.3 Error Suggestion (AA)). - Keep the field's own error under the control (3.3.1 Error Identification (A)): the summary adds to it.
- Update
document.titlewithprefixDocumentTitleunless a router owns the title, then do it there witherrorSummary.titlePrefix. - Remove the summary when the form has no errors; never show it while the user types.
Visual and modes#
- Focus indicator: the summary shows a focus ring when the browser treats the focus as keyboard focus; the links have the usual link ring.
- Target size: the links sit in a list with the theme's spacing and are at least 24 by 24 CSS pixels (2.5.8 Target Size (Minimum) (AA)).
- forced-colors behaviour: the Alert's bar uses the system's text colour, and the status icon and word still say danger.
- reduced-motion behaviour: scrolling is instant, never smooth.
Focus management#
- Initial focus: on mount, and each time
focusKeychanges, the summary root takes focus (focus()ontabindex="-1"). With nofocusKey, once on mount.disableAutoFocusskips both, for a static preview where the move would scroll the page (focus › disableAutoFocus leaves focus where it was, on mount and when focusKey changes); an app leaves it off. It is rendered only while there are errors and never updates while the user types. - A link:
preventDefault,focus({ preventScroll: true })on the control with that id, then the control's label (label[for]) or its fieldset's legend is scrolled into view. Never smooth scrolling. A click with Ctrl, Meta, Shift, Alt or a non-primary button, and a link whose target is missing, are left to the browser (the hash navigation). - A link whose control can't take focus (hidden, disabled, not focusable):
focus()leavesdocument.activeElementelsewhere, so the link does notpreventDefaultand the browser's own hash jump runs. A development warningerror-summary-control-unfocusable:<id>is shown once per id (error-summary.test.tsx › links › a link whose control cannot take focus is left to the browser and warns once). After a native jump to a non-focusable target focus can fall tobody; point the link at the focusable control. - A group of options: link to the first option's id.
- Trap: no. Restore to: not applicable. After a fix the consumer removes the summary on the next submit; focus then moves to the new one or, with no errors, to where the submit goes.
- Never obscured by: the summary is scrolled into view by
focus(). Pair it withscroll-padding-topfor a sticky header andscroll-padding-bottomfor the on-screen keyboard (2.4.11 Focus Not Obscured (Minimum) (AA)). - The focus ring shows when the browser treats the focus as keyboard focus (
:focus-visible).
Warning: Don't forget
If your page has a sticky header, set scroll-padding-top on the page, so the focused summary isn’t hidden behind it (2.4.11 Focus Not Obscured (Minimum), AA).
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 |
|---|---|---|
| Root | none | The Root is an Alert.Danger, a named group that takes focus |
| Title | h2 (default), h3, h4, h5, h6 | The level the page's outline needs. No h1 (the page's title) and no p (the summary needs a heading for the group's name) |
| List | ul (default), ol | A list of problems, optionally numbered |
| Item, Link | none | <li> and <a href="#id">: the link must stay a link (4.1.2 Name, Role, Value (A)) |
WCAG success criteria#
- 3.3.1 Error Identification (A), 3.3.3 Error Suggestion (AA): each problem is named in text, linked to its field (
links › each link goes to its control id and reads the field error text). - 2.4.3 Focus Order (A): focus moves to the summary on a failed submit and then to the field (
focus › moves focus to the summary on mount,focus › moves focus again when focusKey changes, even from a link inside it,› a link moves focus to the field). - 4.1.3 Status Messages (AA): the summary takes focus, so it needs no live region (
announcements › nothing is said in the Announcer). - 1.3.1 Info and Relationships (A), 4.1.2 Name, Role, Value (A): native list and links, a named group. 2.4.2 Page Titled (A): the prefix on the page title (
document title › prefixes the page title while shown and restores it on unmount). - 2.4.7 Focus Visible (AA): the summary and the links show a focus ring (Visual / modes; reviewed in the stories, no named test).
- 1.4.1 Use of Color (A): the links are underlined and the Alert's danger word and icon say danger, so colour is not the only cue (theme properties, no named test).
- 1.4.3 Contrast (Minimum) (AA): the theme's colour pairs for the Alert meet the minimum contrast, checked automatically for every theme, and axe finds no violation (
accessibility › no axe violations with the summary focused). - 2.5.8 Target Size (Minimum) (AA): the links are at least 24 by 24 CSS pixels (Visual / modes; reviewed in the stories, no named test).
- Axe: no violations with the summary focused (
accessibility › no axe violations with the summary focused).
Keyboard#
- Focus
- native
- Selection follows focus
- n/a
- Arrows wrap
- n/a
- Shortcuts
- none
The summary is not a widget. Focus is moved to it by script, once per submit; then the links are native Tab stops in DOM order. A link's activation focuses the field. The component never intercepts a key.
| Key | Where | What happens |
|---|---|---|
| Tab | the summary has focus | Moves to the first link in the list Test: error-summary.test.tsx › keyboard › Tab from the summary moves to the first link |
| Tab | on a link | Moves to the next link, and after the last one on into the page (the form's first field) Test: error-summary.test.tsx › keyboard › Tab moves through the links and then out of the summary |
| Shift+Tab | on the first link | Moves to the stop before the summary: the summary itself is not a Tab stop Test: error-summary.test.tsx › keyboard › Shift+Tab from the first link goes to the stop before the summary |
| Enter | on a link | Moves focus to the field and scrolls its label into view Test: error-summary.test.tsx › keyboard › Enter on a link moves focus to its field |
API reference#
import { ErrorSummary, useErrorSummary } from '@kvirn-ui/react'ErrorSummary.Root
Renders An Alert.Danger: a <div> with the role group, named by the Title, and tabindex="-1", so code can move focus to it and it is not a Tab stop. It has no live region. It takes every attribute of a <div> and passes ref to it. Also exported as ErrorSummaryRoot. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
focusKey | string | number | – | Moves focus to the summary on mount and each time it changes. Pass the submit count, so a second failed submit moves focus again. Without it, focus moves once, on mount. |
disableAutoFocus | boolean | false | Never moves focus to the summary, on mount or when focusKey changes. For a static preview, such as a docs page or a screenshot, where the move would scroll the page. Leave it off in an app: the focus move is how the summary is announced. |
prefixDocumentTitle | boolean | false | Puts the text errorSummary.titlePrefix (“Error:”) before the page title (document.title) while the summary is shown, and restores the title when it is removed. Leave it off if your router owns the title. |
messages | Partial<KvirnMessages['errorSummary']> | – | Per-instance override of the title and of the page title prefix, such as { title: "Fix the errors" }. |
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-error-summary | always | The part class. The default theme styles it. |
kv-alert, kv-alert--danger | always | From Alert.Danger: the danger colour, icon and status word. |
role | group | A named group, not an alert and not a landmark. |
tabindex | -1 | Focusable by script, so it takes focus; not a Tab stop. |
aria-labelledby | the Title’s id | Names the group. |
ErrorSummary.Title
Renders <h2> with the role heading, level 2, from Alert.Title. The status word “Error:” comes first. Without children it reads errorSummary.title. Also exported as ErrorSummaryTitle.
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'h2' | Sets the heading level, for example as="h3". The status word stays. There is no h1 and no p: the summary needs a heading for the group’s name. Children replace the default text. |
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-alert-title | always | From Alert.Title. |
kv-alert-status | always | The status word that starts the Title. |
id | generated | Names the group. |
ErrorSummary.List
Renders <ul> with the role list, one Item per problem. Also exported as ErrorSummaryList.
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'ul' | 'ol' | 'ul' | A list of problems, optionally numbered. |
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-error-summary-list | always | The part class. |
role | list | Explicit, because the theme draws no markers and Safari then drops the list. |
ErrorSummary.Item
Renders <li> with the role listitem, holding one Link. Also exported as ErrorSummaryItem.
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-error-summary-item | always | The part class. |
ErrorSummary.Link
Renders <a href="#controlId"> with the role link. Its text is the field’s own error text. A click or Enter focuses the control and scrolls its label (or, for a group, its legend) into view. With a modifier key, when no element has the id, or when the control can’t take focus, the browser handles it. It takes every attribute of an <a> except href, and passes ref to it. Also exported as ErrorSummaryLink.
| Prop | Type | Default | Description |
|---|---|---|---|
controlId | string | Required | The id of the control the error is about, or of a group’s first option. Sets href to “#” plus the id. Set the id with controlId on Field.Root. |
ref | Ref<HTMLAnchorElement> | – | Reaches the link. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-link | always | The Link class. |
kv-error-summary-link | always | The part class. |
useErrorSummary
Options
| Prop | Type | Default | Description |
|---|---|---|---|
focusKey | string | number | – | Moves focus to the summary on mount and each time it changes. Pass the submit count. |
disableAutoFocus | boolean | false | Never moves focus to the summary. For a static preview only. |
prefixDocumentTitle | boolean | false | Puts errorSummary.titlePrefix before document.title while the summary is shown. |
messages | Partial<KvirnMessages['errorSummary']> | – | Per-instance override of the title and of the page title prefix, such as { title: "Fix the errors" }. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
rootProps | ErrorSummaryRootPartProps | – | Spread on the summary’s element, usually an Alert.Danger: class, role group, tabIndex -1, aria-labelledby and a callback ref that moves focus. |
titleProps | ErrorSummaryTitlePartProps | – | Spread on the heading. The id names the group. |
listProps | ErrorSummaryListPartProps | – | Spread on the <ul>: class and role list. |
itemProps | ErrorSummaryItemPartProps | – | Spread on an <li>. |
getLinkProps | (controlId: string) => ErrorSummaryLinkPartProps | – | Spread on an <a>: class, href and the click handler that focuses the control and scrolls its label into view. A modified click and a missing control are left to the browser. |
title | string | – | The text errorSummary.title: the default text of the heading. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one ErrorSummary, pass its messages prop.
errorSummary.title
The default text of the Title. It names the focused group.
| Language | Default text |
|---|---|
| Svenska | Det finns ett problem |
| Suomi | Lomakkeessa on virheitä |
| Norsk bokmål | Det er et problem |
| Norsk nynorsk | Det er eit problem |
| English | There is a problem |
errorSummary.titlePrefix
Put before the page title while the summary is shown, with prefixDocumentTitle.
| Language | Default text |
|---|---|
| Svenska | Fel: |
| Suomi | Virhe: |
| Norsk bokmål | Feil: |
| Norsk nynorsk | Feil: |
| English | Error: |
Known issues#
- A screen reader may read only the group's title when it takes focus. The first Tab reads the first error.
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 | error-summary.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | error-summary.test.tsx (axe and role, name and state): it is an Alert.Danger group named by its title, with a list of links |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 4 rows, each names a test in error-summary.test.tsx |
| Focus order and management | pass | n/a | pass | error-summary.test.tsx: focus › moves focus to the summary on mount |
| 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#
With a screen reader and the keyboard, try:
- Submit an empty form: focus moves to the summary and "Error: There is a problem" is read.
- Tab: the first error link is read.
- Press Enter on a link: focus moves to the field, and its label, "invalid" and the error are read.
- Submit again: focus returns to the summary.
- Shift+Tab on the first link goes to the stop before the summary.
- With
prefixDocumentTitle, the tab title starts with "Error:" while the summary shows.