When to use it#
- Use it for any short list: related links, footer links, what to bring, the steps of an application.
- It has no marker. Add
kv-list--bulletfor bullets. Useas="ol"withkv-list--decimalwhen the order matters. - A list of links is a list, not a navigation. When it is navigation, put it in a
navwith a name. - Not for a menu that marks the current page: use Navigation. Not for a label with its value: use a DefinitionList. Not for columns of data: use a Table.
Example#
import { Link, List } from '@kvirn-ui/react'
import { useListTexts } from './texts.ts'
export function DefaultList() {
const { texts } = useListTexts()
return (
<List.Root>
<List.Item>
<Link href="#building-permits">{texts.buildingPermits}</Link>
</List.Item>
<List.Item>
<Link href="#waste">{texts.waste}</Link>
</List.Item>
<List.Item>
<Link href="#school-transport">{texts.schoolTransport}</Link>
</List.Item>
</List.Root>
)
}Use cases#
Related services at the end of a page
Links to other services at the end of a page. Put them in a named nav, so screen reader users who jump between the page’s navigation areas can find them.
import { Link, List } from '@kvirn-ui/react'
import { useListTexts } from './texts.ts'
export function RelatedLinks() {
const { texts } = useListTexts()
return (
<nav aria-label={texts.relatedLabel}>
<List.Root>
<List.Item>
<Link href="#building-permits">{texts.buildingPermits}</Link>
</List.Item>
<List.Item>
<Link href="#waste">{texts.waste}</Link>
</List.Item>
<List.Item>
<Link href="#school-transport">{texts.schoolTransport}</Link>
</List.Item>
</List.Root>
</nav>
)
}Warning: Don't forget
Give the nav a name. An unnamed nav is announced only as “navigation”, so people can’t tell it from the page’s other navigation areas (1.3.1 Info and Relationships, 2.4.1 Bypass Blocks).
How to apply for a parking permit
Steps in a fixed order. An ordered list tells a screen reader that the order matters, and the decimal class shows the numbers.
How to apply for a parking permit
- Fill in the application.
- Attach a copy of your vehicle registration.
- Wait for the decision. It arrives in your inbox on My pages.
import { Heading, List } from '@kvirn-ui/react'
import { useId } from 'react'
import { useListTexts } from './texts.ts'
export function Steps() {
const { texts } = useListTexts()
const headingId = useId()
return (
<section aria-labelledby={headingId}>
<Heading as="h4" id={headingId}>
{texts.stepsHeading}
</Heading>
<List.Root as="ol" className="kv-list--decimal">
<List.Item>{texts.stepApply}</List.Item>
<List.Item>{texts.stepAttach}</List.Item>
<List.Item>{texts.stepWait}</List.Item>
</List.Root>
</section>
)
}Props in this example:
ason List.Root
Services with sub-services
Put an inner list inside the List.Item it belongs to. The bullet class marks each level.
import { Heading, Link, List } from '@kvirn-ui/react'
import { useId } from 'react'
import { useListTexts } from './texts.ts'
export function Nested() {
const { texts } = useListTexts()
const headingId = useId()
return (
<section aria-labelledby={headingId}>
<Heading as="h4" id={headingId}>
{texts.topicsHeading}
</Heading>
<List.Root className="kv-list--bullet">
<List.Item>
<Link href="#housing">{texts.topicHousing}</Link>
<List.Root className="kv-list--bullet kv-list--gap-2">
<List.Item>
<Link href="#building-permits">{texts.topicPermits}</Link>
</List.Item>
<List.Item>
<Link href="#housing-adaptation-grant">{texts.topicAdaptation}</Link>
</List.Item>
</List.Root>
</List.Item>
<List.Item>
<Link href="#schools">{texts.topicSchool}</Link>
<List.Root className="kv-list--bullet kv-list--gap-2">
<List.Item>
<Link href="#school-transport">{texts.topicTransport}</Link>
</List.Item>
<List.Item>
<Link href="#school-meals">{texts.topicMeals}</Link>
</List.Item>
</List.Root>
</List.Item>
</List.Root>
</section>
)
}Accessibility#
What it does for you#
- APG pattern: none. List is static content, not a widget.
- Deviations: none
- Native elements used:
<ul>(default) or<ol>withas="ol", and<li>.asis'ul' | 'ol'only.
List is the native list with a class and a few typed choices, so link lists, related links and footer link groups are one component instead of a <ul role="list"> repeated per pattern. It adds no text, no behaviour and no tabindex. A list of links is a list, not a navigation: the consumer wraps it in a named nav when it is one.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| List.Root | <ul> or <ol> → list | role="list", always | class="kv-list", plus kv-list--bullet or -decimal for a marker, and kv-list--gap-2, -6 or -8 for another gap, all added by the consumer (the default adds none). WebKit and VoiceOver drop the list role under list-style: none, so the list always carries role="list". A role of your own wins |
| List.Item | <li> → listitem | none | No class, no role. Attributes and the ref reach the element. A link item is <List.Item><Link.Root href>…</Link.Root></List.Item> |
| List.Root | never | no name, tabindex, aria-hidden | No aria-label by default. No heading, handler or live region |
kv-list--decimal is for as="ol": on a ul the numbers say nothing about order to assistive technology. kv-list--bullet on an ol is allowed: the order is still announced.
It announces nothing.
What you need to do#
- A list of links is a list, not a navigation. When it is navigation, wrap it in a
<nav>with an accessible name (aria-labeloraria-labelledby), and don't repeat the name inside it (1.3.1, 2.4.1). - Link text makes sense alone. Each link names its target without the text around it (2.4.4).
- Use
as="ol"when order matters, andkv-list--decimalonly then (1.3.1). - Items are
List.Item. Put nothing butList.Itemdirectly inList.Root; a nested list goes inside an item. - Language. Text in another language goes in a nested
KvirnProvider, withuseLocale().localePropson your own element (3.1.2).
Warning: Don't forget
Use the decimal class with as="ol", not with a plain list. On a plain list the numbers you see say nothing about order to a screen reader, so that information would be lost (1.3.1 Info and Relationships).
Visual and modes#
Headless: List ships no CSS. With @kvirn-ui/theme/theme.css, kv-list stacks the items with a gap between them, with no marker and no indent. bullet and decimal draw outside markers in the text colour, indented in rem (1.4.4). Target size and the focus indicator belong to the links inside. forced-colors: markers use the text colour, which the system maps. Motion: none.
Focus management#
- Initial focus: not moved. List never moves focus.
- Trap: no.
- Restore to: not applicable.
Allowed elements#
A tag outside the list changes the page's outline or semantics (1.3.1, 4.1.2). List.Root takes ul (default) or ol; another tag warns once (as-not-allowed) and falls back to ul. List.Item is a native <li> and has no as.
WCAG success criteria#
- 1.3.1 Info and Relationships (A), 4.1.2 Name, Role, Value (A): a list is a list with a count, with or without markers.
- 1.4.4 Resize Text: sizes are in rem.
Keyboard#
List has no keys of its own. What you put in it keeps its own keys.
API reference#
import { List } from '@kvirn-ui/react'List.Root
Renders <ul>, or <ol> with as="ol", with the role list. It takes every attribute of a <ul> and passes ref to it. It has no state, no hook and no strings. Also exported as ListRoot. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'ul' | 'ol' | 'ul' | Changes the element: use ol when the order matters. Only ul and ol are allowed. |
ref | Ref<HTMLElement> | – | Reaches the list, whichever element it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
role | "list", always | Safari and VoiceOver drop the list role when a list has no marker, so the role is always there. A role of your own wins. |
kv-list | always | The part class: no marker and no indent. Your className joins it. |
kv-list--bullet, kv-list--decimal | class you add | A marker outside the text. Use decimal only with as="ol": numbers on a ul say nothing about order to assistive technology. |
kv-list--gap-2, kv-list--gap-6, kv-list--gap-8 | class you add | Another space between the items. gap-2 is tighter than the default, gap-6 and gap-8 are wider. |
List.Item
Renders <li> with no class and no role of its own. It takes every attribute of an <li> and passes ref to it. Also exported as ListItem. Put a Link or text in it, and a nested List.Root when the item has sub-items.
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<HTMLLIElement> | – | Reaches the <li> element. |
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 | list.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | list.test.tsx › renders a ul or an ol with li items and keeps its class next to a consumer className; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | list.test.tsx › renders a ul or an ol with li items and keeps its class next to a consumer className (asserts no tabindex) |
| 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 |