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.

DefinitionList

Terms with their descriptions, and optionally a link to change each, as one native description list. Every link says what it changes, because its name is built from the row’s label.

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

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#

Name
Anna Svensson
Change
Email address
anna.svensson@example.com
Change

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.

Check your answers

Name
Anna Svensson
Change
Email address
anna.svensson@example.com
Change
Address
Storgatan 12, 111 22 Stockholm
Change

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

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

Email address
anna.svensson@example.com
Change
Phone number
Not provided
Add

Props in this example:

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.

Children
Maja, born 2019
Olle, born 2022
Change

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.

Name
Anna Svensson
Change

Props in this example:

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.

PartElement / roleARIANotes
Root<dl> (no role)none<div> rows are allowed inside a <dl>, and keep each term with its descriptions
Row<div>, genericnoneOne term and one or more descriptions. Gives its Term an id for the Change link, or follows the Term's own id
Term<dt> → termnoneThe 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> → definitionnoneThe answer. Wraps, never truncates
Actions<dd> → definitionnoneHolds links. A second definition of the same term
Change<a> → linkaria-labelledby = its own id, then the Term's idVisible 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), not history.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 Field inside 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 partnoneThe <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.

KeyWhereWhat happens
Tabbefore the listMoves focus to the first Change link, skipping the text
Test: definition-list.test.tsx › keyboard › Tab moves through the Change links in row order
Tabon a Change linkMoves 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+Tabon a Change linkMoves 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
Enteron a Change linkFollows 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.

PropTypeDefaultDescription
refRef<HTMLElement>–Reaches the element, whichever it is.
Class or attributeValuesMeaning
kv-definition-listalwaysThe 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.

PropTypeDefaultDescription
refRef<HTMLElement>–Reaches the element, whichever it is.
Class or attributeValuesMeaning
kv-definition-list-rowalwaysThe 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.

PropTypeDefaultDescription
refRef<HTMLElement>–Reaches the element, whichever it is.
Class or attributeValuesMeaning
kv-definition-list-termalwaysThe part class.
idgenerated, inside a RowThe 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.

PropTypeDefaultDescription
refRef<HTMLElement>–Reaches the element, whichever it is.
Class or attributeValuesMeaning
kv-definition-list-descriptionalwaysThe 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.

PropTypeDefaultDescription
refRef<HTMLElement>–Reaches the element, whichever it is.
Class or attributeValuesMeaning
kv-definition-list-actionsalwaysThe 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.

PropTypeDefaultDescription
childrenReactNodethe message definitionList.changeThe visible text of the link, such as “Add”. The term is still added to the accessible name.
messagesPartial<KvirnMessages['definitionList']>–Per-instance override of the visible text, such as { change: "Add" }. The term is still added to the accessible name.
refRef<HTMLAnchorElement>–Reaches the link.
Class or attributeValuesMeaning
kv-linkalwaysThe Link class, so the link looks like every other link.
kv-definition-list-changealwaysThe part class.
idgenerated, inside a RowThe link’s own id. Its name starts with its own text, then the Term’s.
aria-labelledbythe link’s id, then the Term’s idBuilds the name: “Change” plus the term. Without a Row it is left off.

useDefinitionList

Options

PropTypeDefaultDescription
messagesPartial<KvirnMessages['definitionList']>–Per-instance override of the visible text of the Change link.

Result

PropTypeDefaultDescription
rootPropsDefinitionListPartProps<"definition-list">–Spread on the <dl>: the class only.
rowPropsDefinitionListPartProps<"definition-list-row">–Spread on the <div> of a row.
termPropsDefinitionListPartProps<"definition-list-term">–Spread on the <dt>. Give it the id you pass to getChangeProps.
descriptionPropsDefinitionListPartProps<"definition-list-description">–Spread on a <dd> that holds an answer.
actionsPropsDefinitionListPartProps<"definition-list-actions">–Spread on the <dd> that holds the links.
changeLabelstring–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.

LanguageDefault text
SvenskaÄndra
SuomiMuuta
Norsk bokmålEndre
Norsk nynorskEndre
EnglishChange

Known issues#

  • In server-rendered HTML the link is named just “Change” until the page script has loaded, when the Term has an id you 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 + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespassn/apassdefinition-list.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apassdefinition-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)passn/apass4 rows, each names a test in definition-list.test.tsx
Focus order and managementpassn/apassdefinition-list.test.tsx: keyboard › Tab moves through the Change links in row order
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#

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