When to use it#
- Use it to show what someone has already given or what a case contains: the last step before they send, a contact card, a case card.
- Put the Change link where the answer is changed, so people don’t have to start again. Leave it out when the value can’t be changed.
- Write a Term for every row, and a Description that says so when there is no answer: “Not provided”, not an empty row.
- Not for a description people edit in place: that is a Field. Not for data with several columns: use a Table.
Example#
import { DefinitionList } from '@kvirn-ui/react'
import { useDefinitionListTexts } from './texts.ts'
export function DefaultDefinitionList() {
const { texts } = useDefinitionListTexts()
return (
<DefinitionList.Root>
<DefinitionList.Row>
<DefinitionList.Term>{texts.name}</DefinitionList.Term>
<DefinitionList.Description>{texts.nameValue}</DefinitionList.Description>
<DefinitionList.Actions>
<DefinitionList.Change href="#step-name" />
</DefinitionList.Actions>
</DefinitionList.Row>
<DefinitionList.Row>
<DefinitionList.Term>{texts.email}</DefinitionList.Term>
<DefinitionList.Description>{texts.emailValue}</DefinitionList.Description>
<DefinitionList.Actions>
<DefinitionList.Change href="#step-email" />
</DefinitionList.Actions>
</DefinitionList.Row>
</DefinitionList.Root>
)
}Use cases#
Check your answers before sending
The last step of a form shows every answer with a link back to the step where it is changed. Each link reads, for example, “Change Name”, so a screen reader user (who hears the page read aloud) can list the links and still know what each one does.
import { Heading, DefinitionList } from '@kvirn-ui/react'
import { useDefinitionListTexts } from './texts.ts'
export function CheckYourAnswers() {
const { texts } = useDefinitionListTexts()
return (
<section aria-labelledby="check-your-answers-heading">
<Heading as="h4" id="check-your-answers-heading">
{texts.heading}
</Heading>
<DefinitionList.Root>
<DefinitionList.Row>
<DefinitionList.Term>{texts.name}</DefinitionList.Term>
<DefinitionList.Description>{texts.nameValue}</DefinitionList.Description>
<DefinitionList.Actions>
<DefinitionList.Change href="#step-name" />
</DefinitionList.Actions>
</DefinitionList.Row>
<DefinitionList.Row>
<DefinitionList.Term>{texts.email}</DefinitionList.Term>
<DefinitionList.Description>{texts.emailValue}</DefinitionList.Description>
<DefinitionList.Actions>
<DefinitionList.Change href="#step-email" />
</DefinitionList.Actions>
</DefinitionList.Row>
<DefinitionList.Row>
<DefinitionList.Term>{texts.address}</DefinitionList.Term>
<DefinitionList.Description>{texts.addressValue}</DefinitionList.Description>
<DefinitionList.Actions>
<DefinitionList.Change href="#step-address" />
</DefinitionList.Actions>
</DefinitionList.Row>
</DefinitionList.Root>
</section>
)
}Warning: Don't forget
Give every row a Term. The link’s name is built from it, and without a Row and a Term it is only “Change” and a development warning says so.
Details of a case, read only
A case card or a contact card shows facts and nothing to change. Leave out Actions, and put a link in a Description when the fact is a document.
Parking permit
- Case number
- PP-2026-0412
- Status
- Being processed
- Case worker
- Erik Lindqvist
- Decision
- Read the decision
import { Card, Heading, Link, DefinitionList } from '@kvirn-ui/react'
import { useDefinitionListTexts } from './texts.ts'
export function CaseCard() {
const { texts } = useDefinitionListTexts()
return (
<Card.Root>
<Card.Header>
<Heading as="h4">{texts.caseHeading}</Heading>
</Card.Header>
<Card.Body>
<DefinitionList.Root>
<DefinitionList.Row>
<DefinitionList.Term>{texts.caseNumber}</DefinitionList.Term>
<DefinitionList.Description>{texts.caseNumberValue}</DefinitionList.Description>
</DefinitionList.Row>
<DefinitionList.Row>
<DefinitionList.Term>{texts.status}</DefinitionList.Term>
<DefinitionList.Description>{texts.statusValue}</DefinitionList.Description>
</DefinitionList.Row>
<DefinitionList.Row>
<DefinitionList.Term>{texts.caseWorker}</DefinitionList.Term>
<DefinitionList.Description>{texts.caseWorkerValue}</DefinitionList.Description>
</DefinitionList.Row>
<DefinitionList.Row>
<DefinitionList.Term>{texts.decision}</DefinitionList.Term>
<DefinitionList.Description>
<Link href="#decision">{texts.decisionLink}</Link>
</DefinitionList.Description>
</DefinitionList.Row>
</DefinitionList.Root>
</Card.Body>
</Card.Root>
)
}Information: Did you know?
The list takes its width from its container, so it fits a Card, a side column or the page. On screens narrower than 40rem the rows stack, with the term above the description.
An answer that is missing
Say that nothing is given, and let the link say what to do. You change the word on the link with the messages prop, and the link’s name is still “Add Phone number”.
import { DefinitionList } from '@kvirn-ui/react'
import { useDefinitionListTexts } from './texts.ts'
export function MissingAnswer() {
const { texts } = useDefinitionListTexts()
return (
<DefinitionList.Root>
<DefinitionList.Row>
<DefinitionList.Term>{texts.email}</DefinitionList.Term>
<DefinitionList.Description>{texts.emailValue}</DefinitionList.Description>
<DefinitionList.Actions>
<DefinitionList.Change href="#step-email" />
</DefinitionList.Actions>
</DefinitionList.Row>
<DefinitionList.Row>
<DefinitionList.Term>{texts.phone}</DefinitionList.Term>
<DefinitionList.Description>{texts.notProvided}</DefinitionList.Description>
<DefinitionList.Actions>
<DefinitionList.Change href="#step-phone" messages={{ change: texts.add }} />
</DefinitionList.Actions>
</DefinitionList.Row>
</DefinitionList.Root>
)
}Props in this example:
messageson DefinitionList.Change
Information: Did you know?
Write “Not provided” in the Description, so everyone knows the answer is missing and not lost. An empty Description leaves the reader with a label and no value.
Several answers to one question
A row can hold more than one Description, for example the children in a household. They stay together with the Term, and the one link changes all of them.
import { DefinitionList } from '@kvirn-ui/react'
import { useDefinitionListTexts } from './texts.ts'
export function SeveralAnswers() {
const { texts } = useDefinitionListTexts()
return (
<DefinitionList.Root>
<DefinitionList.Row>
<DefinitionList.Term>{texts.children}</DefinitionList.Term>
<DefinitionList.Description>{texts.childOne}</DefinitionList.Description>
<DefinitionList.Description>{texts.childTwo}</DefinitionList.Description>
<DefinitionList.Actions>
<DefinitionList.Change href="#step-children" />
</DefinitionList.Actions>
</DefinitionList.Row>
</DefinitionList.Root>
)
}With your own elements
When the markup is yours, take the class names and the link’s props from the hook and put them on a native description list. Give the Term an id and pass it to getChangeProps, and the link gets its name.
import { useDefinitionList } from '@kvirn-ui/react'
import { useId } from 'react'
import { useDefinitionListTexts } from './texts.ts'
export function OwnMarkup() {
const { texts } = useDefinitionListTexts()
const definitionList = useDefinitionList()
const termId = useId()
const changeId = useId()
return (
<dl {...definitionList.rootProps}>
<div {...definitionList.rowProps}>
<dt {...definitionList.termProps} id={termId}>
{texts.name}
</dt>
<dd {...definitionList.descriptionProps}>{texts.nameValue}</dd>
<dd {...definitionList.actionsProps}>
<a {...definitionList.getChangeProps({ id: changeId, termId })} href="#step-name">
{definitionList.changeLabel}
</a>
</dd>
</div>
</dl>
)
}Props in this example:
getChangePropson useDefinitionList (result)
Accessibility#
What it does for you#
- APG pattern: none. A native description list (
<dl>), the same pattern as GOV.UK's Summary list. - Deviations: none.
- Native elements used:
<dl>,<div>row groups,<dt>,<dd>and<a>(the Change link).
Rows of a term, a description and optional actions: the answers on a check-your-answers page, a contact card, a case card. It is read-only: a description you can edit is a Field, and the row's action is a link to where it is changed.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Root | <dl> (no role) | none | <div> rows are allowed inside a <dl>, and keep each term with its descriptions |
| Row | <div>, generic | none | One term and one or more descriptions. Gives its Term an id for the Change link, or follows the Term's own id |
| Term | <dt> → term | none | The label. A consumer id is kept and registered with the Row, so the Change link's aria-labelledby follows it. If no element has that id the Change link warns once in development. |
| Description | <dd> → definition | none | The answer. Wraps, never truncates |
| Actions | <dd> → definition | none | Holds links. A second definition of the same term |
| Change | <a> → link | aria-labelledby = its own id, then the Term's id | Visible text is definitionList.change ("Change"). The accessible name is "Change" plus the term, so the link's purpose is clear when links are listed on their own (2.4.4 Link Purpose (In Context), A) and the name contains the visible text (2.5.3 Label in Name, A) |
It announces nothing.
What you need to do#
- Every row has a Term. The Change link's name is built from it.
- A Change link goes to where the answer is changed (
href), nothistory.back(), and returns to the page after saving (3.3.7 Redundant Entry, A, asks you not to make people re-enter what they gave). - A Description with no answer says so ("Not provided"), never an empty
<dd>. - Headings for a list of lists are yours: the component renders none.
- Don't put a
Fieldinside a row: it is for display, not for editing.
Warning: Don't forget
After someone changes an answer, send them back to the summary with every other answer still filled in. 3.3.7 Redundant Entry (A) asks you not to make people enter the same information again.
Visual and modes#
- Focus indicator: the same focus ring as every Link (2.4.7 Focus Visible, AA).
- Target size: the Change link is at least 24 CSS pixels high (2.5.8 Target Size (Minimum), AA).
- forced-colors behaviour: the row dividers use the system's text colour, and links keep the system's link colour.
- reduced-motion behaviour: nothing animates.
- Reflow: on a narrow screen the rows stack (term, description, actions), and the reflow sweep checks that nothing scrolls sideways at 320 CSS pixels (1.4.10 Reflow, AA).
Focus management#
- Initial focus: none. Nothing moves focus.
- Trap: no. Restore to: not applicable.
- Never obscured by: nothing is sticky. The link shows a focus ring (2.4.7 Focus Visible, AA).
Allowed elements#
No part takes as: a ul or span instead would drop the term and definition relationship (1.3.1 Info and Relationships, A; 4.1.2 Name, Role, Value, A).
| Part | `as` | Why |
|---|---|---|
| every part | none | The <dl>, <div>, <dt> and <dd> are the structure of the term and its definitions (1.3.1 Info and Relationships, A), and Change is an <a href>. A list or a router link is built from useDefinitionList with your own elements |
WCAG success criteria#
- 1.3.1 Info and Relationships (A): native
dl,dt,dd. - 2.4.4 Link Purpose (In Context) (A), 2.5.3 Label in Name (A): the name is "Change" plus the term and starts with the visible text.
- 2.4.7 Focus Visible (AA): the link shows a focus ring. The ring itself is checked by eye.
- 2.5.8 Target Size (Minimum) (AA): the Change link is at least 24 CSS pixels high, from the theme. This is checked by eye.
- 3.3.7 Redundant Entry (A): your duty (Consumer responsibilities): the Change link returns to the page after saving. This is not checked automatically.
- 1.4.10 Reflow (AA): the stacked layout. The reflow sweep checks that nothing scrolls sideways at 320 CSS pixels.
- Axe finds no violations in any story.
Keyboard#
- Focus
- native
- Selection follows focus
- n/a
- Arrows wrap
- n/a
- Shortcuts
- none
The list is not a widget. Its only focusable parts are the Change links (and any links you put in a Description), in DOM order. The component adds no Tab stop, no key handler and no tabindex.
| Key | Where | What happens |
|---|---|---|
| Tab | before the list | Moves focus to the first Change link, skipping the text Test: definition-list.test.tsx › keyboard › Tab moves through the Change links in row order |
| Tab | on a Change link | Moves to the next row's Change link, then on into the page Test: definition-list.test.tsx › keyboard › Tab moves through the Change links in row order |
| Shift+Tab | on a Change link | Moves to the previous row's Change link, then to the stop before Test: definition-list.test.tsx › keyboard › Shift+Tab moves back through the Change links |
| Enter | on a Change link | Follows the link (native) Test: definition-list.test.tsx › keyboard › Enter on a Change link follows it |
API reference#
import { DefinitionList, useDefinitionList } from '@kvirn-ui/react'DefinitionList.Root
Renders <dl> with no role of its own. It takes every attribute of a <dl> and passes ref to it. Its direct children are Rows. Also exported as DefinitionListRoot. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-definition-list | always | The part class. The default theme styles it. |
DefinitionList.Row
Renders <div> with no role of its own. It takes every attribute of a <div> and passes ref to it. It keeps one term with its descriptions and gives the Term an id for the Change link. Also exported as DefinitionListRow.
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-definition-list-row | always | The part class. |
DefinitionList.Term
Renders <dt> with no role of its own. It takes every attribute of a <dt> and passes ref to it. The label. It needs text, because the Change link’s name is built from it. Also exported as DefinitionListTerm.
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-definition-list-term | always | The part class. |
id | generated, inside a Row | The Row gives the Term an id, which names the Change link. An id you set yourself is kept and still names the link. |
DefinitionList.Description
Renders <dd> with no role of its own. It takes every attribute of a <dd> and passes ref to it. The answer. A row can hold more than one. Also exported as DefinitionListDescription.
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-definition-list-description | always | The part class. |
DefinitionList.Actions
Renders <dd> with no role of its own. It takes every attribute of a <dd> and passes ref to it. Holds the row’s links, such as Change. Also exported as DefinitionListActions.
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-definition-list-actions | always | The part class. |
DefinitionList.Change
Renders <a> with the role link. Its text is the message definitionList.change unless you pass children, and its name is that text plus the Term’s. Give it the href of the step where the answer is changed. It takes every attribute of an <a> and passes ref to it. Also exported as DefinitionListChange.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | the message definitionList.change | The visible text of the link, such as “Add”. The term is still added to the accessible name. |
messages | Partial<KvirnMessages['definitionList']> | – | Per-instance override of the visible text, such as { change: "Add" }. The term is still added to the accessible name. |
ref | Ref<HTMLAnchorElement> | – | Reaches the link. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-link | always | The Link class, so the link looks like every other link. |
kv-definition-list-change | always | The part class. |
id | generated, inside a Row | The link’s own id. Its name starts with its own text, then the Term’s. |
aria-labelledby | the link’s id, then the Term’s id | Builds the name: “Change” plus the term. Without a Row it is left off. |
useDefinitionList
Options
| Prop | Type | Default | Description |
|---|---|---|---|
messages | Partial<KvirnMessages['definitionList']> | – | Per-instance override of the visible text of the Change link. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
rootProps | DefinitionListPartProps<"definition-list"> | – | Spread on the <dl>: the class only. |
rowProps | DefinitionListPartProps<"definition-list-row"> | – | Spread on the <div> of a row. |
termProps | DefinitionListPartProps<"definition-list-term"> | – | Spread on the <dt>. Give it the id you pass to getChangeProps. |
descriptionProps | DefinitionListPartProps<"definition-list-description"> | – | Spread on a <dd> that holds an answer. |
actionsProps | DefinitionListPartProps<"definition-list-actions"> | – | Spread on the <dd> that holds the links. |
changeLabel | string | – | The text “Change”, in the language of the provider: the link’s visible text. |
getChangeProps | (ids: { id: string; termId: string }) => DefinitionListChangePartProps | – | The link’s class, its own id and aria-labelledby, so its name is “Change” plus the term. id is the link’s, termId the id of the row’s <dt>. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one DefinitionList, pass its messages prop.
definitionList.change
The visible text of the Change link. The row’s term is added to its accessible name.
| Language | Default text |
|---|---|
| Svenska | Ändra |
| Suomi | Muuta |
| Norsk bokmål | Endre |
| Norsk nynorsk | Endre |
| English | Change |
Known issues#
- In server-rendered HTML the link is named just “Change” until the page script has loaded, when the Term has an
idyou set yourself. Use the generated id, or accept the short name.
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 | definition-list.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | definition-list.test.tsx (axe and role, name and state): it adds no role, no tabindex and no data attribute of its own |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 4 rows, each names a test in definition-list.test.tsx |
| Focus order and management | pass | n/a | pass | definition-list.test.tsx: keyboard › Tab moves through the Change links in row order |
| 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#
- Tab through the page: focus stops on each Change link in row order, and on nothing else in the list.
- Each Change link reads "Change" plus its row's label ("Change Name"), never just "Change", also in the links list.
- With the screen reader's list and term commands, each term is read with its answer(s). In a row with two answers, both are read after the term.
- Press Enter on a Change link: it goes to the step where the answer is changed.
- At 400% zoom or 320px, the rows stack, term first, and nothing is cut off.