When to use it#
- Use a table for data that has rows and columns: payments, cases, a list a case worker compares.
- Choose a row header, such as a name or a case number, so each row has a title and each checkbox or button says which row it belongs to.
- For long data, split it into pages or add a filter first. Virtualize (draw only the rows near the scroll position) last: rows that are not drawn cannot be found with find in page, are not printed and are out of reach of a screen reader’s browse mode.
- Not for layout, or for a list of cards. A table that turns into blocks on a small screen loses its meaning: let it scroll sideways inside the scroll region instead.
- Not for editing cells or a spreadsheet. Table has no column resizing, reordering, editable cells or multi-sort.
Example#
| Month | Payout date | Amount (SEK) |
|---|---|---|
| January | 1/23/26 | 1,050 |
| February | 2/25/26 | 1,050 |
| March | 3/25/26 | 1,050 |
| Total | 3,150 |
import { Table, useFormat } from '@kvirn-ui/react'
import { useId } from 'react'
import { useTableTexts } from './texts.ts'
const payments = [
{ id: 'p1', month: 'january', date: '2026-01-23', amount: 1050 },
{ id: 'p2', month: 'february', date: '2026-02-25', amount: 1050 },
{ id: 'p3', month: 'march', date: '2026-03-25', amount: 1050 },
] as const
export function DefaultTable() {
const { texts } = useTableTexts()
const format = useFormat()
const captionId = useId()
const total = payments.reduce((sum, payment) => sum + payment.amount, 0)
return (
<Table.ScrollRegion aria-labelledby={captionId}>
<Table.Root>
<Table.Caption id={captionId}>{texts.paymentsCaption}</Table.Caption>
<Table.Head>
<Table.Row>
<Table.ColumnHeader>{texts.month}</Table.ColumnHeader>
<Table.ColumnHeader>{texts.payoutDate}</Table.ColumnHeader>
<Table.ColumnHeader className="kv-table-column-header--numeric">
{texts.amountPaid}
</Table.ColumnHeader>
</Table.Row>
</Table.Head>
<Table.Body>
{payments.map((payment) => (
<Table.Row key={payment.id}>
<Table.RowHeader>{texts[payment.month]}</Table.RowHeader>
<Table.Cell>{format.date(payment.date, { dateStyle: 'short' })}</Table.Cell>
<Table.Cell className="kv-table-cell--numeric">
{format.number(payment.amount)}
</Table.Cell>
</Table.Row>
))}
</Table.Body>
<Table.Foot>
<Table.Row>
<Table.RowHeader>{texts.total}</Table.RowHeader>
<Table.Cell />
<Table.Cell className="kv-table-cell--numeric">{format.number(total)}</Table.Cell>
</Table.Row>
</Table.Foot>
</Table.Root>
</Table.ScrollRegion>
)
}Use cases#
A table the user can sort
Put the sort in the column header, so a user can order cases by name or amount. Only one column is sorted at a time, and each change is announced. You choose the language of the order. This example sorts in Swedish, so å, ä and ö come after z.
| Handler | |||
|---|---|---|---|
| Anna Svensson | BN 2026-0142 | 4,200 | Karin Lund |
| Erik Lindqvist | BN 2026-0163 | 12,500 | Karin Lund |
| Zacharias Nilsson | BN 2026-0171 | 960 | Maria Berg |
| Åsa Öberg | BN 2026-0157 | 1,850 | Johan Ek |
| Ärlig Holm | BN 2026-0188 | 7,300 | Johan Ek |
import {
Table,
createColumnHelper,
createLocaleSortFn,
createSortedRowModel,
rowSortingFeature,
tableFeatures,
useFormat,
useTable,
} from '@kvirn-ui/react'
import { useMemo } from 'react'
import { cases } from './cases.ts'
import type { CaseRecord } from './cases.ts'
import { useTableTexts } from './texts.ts'
// The names are Swedish, so the extra Swedish letters sort after z.
const features = tableFeatures({
rowSortingFeature,
sortedRowModel: createSortedRowModel(),
sortFns: { locale: createLocaleSortFn('sv') },
})
export function SortableCases() {
const { texts } = useTableTexts()
const format = useFormat()
const columns = useMemo(() => {
const column = createColumnHelper<typeof features, CaseRecord>()
return column.columns([
column.accessor('name', { header: texts.name, sortFn: 'locale' }),
column.accessor('caseNumber', { header: texts.caseNumber }),
column.accessor('amount', {
header: texts.amount,
cell: (info) => format.number(info.getValue()),
}),
column.accessor('handler', { header: texts.handler, enableSorting: false }),
])
}, [texts, format])
const list = useTable({
features,
columns,
data: cases,
getRowId: (record) => record.id,
rowHeader: 'name',
initialState: { sorting: [{ id: 'name', desc: false }] },
})
return (
<Table.ScrollRegion table={list}>
<Table.Root table={list}>
<Table.Caption>{texts.casesCaption}</Table.Caption>
<Table.Head>
{list.table.getHeaderGroups().map((headerGroup) => (
<Table.Row key={headerGroup.id} headerGroup={headerGroup}>
{headerGroup.headers.map((header) => (
<Table.ColumnHeader
key={header.id}
header={header}
className={
header.column.id === 'amount' ? 'kv-table-column-header--numeric' : undefined
}
>
{header.column.getCanSort() ? <Table.SortButton header={header} /> : null}
</Table.ColumnHeader>
))}
</Table.Row>
))}
</Table.Head>
<Table.Body>
{(row) => (
<Table.Row key={row.id} row={row}>
{row.getAllCells().map((cell) => (
<Table.Cell
key={cell.id}
cell={cell}
className={cell.column.id === 'amount' ? 'kv-table-cell--numeric' : undefined}
/>
))}
</Table.Row>
)}
</Table.Body>
<Table.Empty />
</Table.Root>
</Table.ScrollRegion>
)
}Props in this example:
featureson useTable (options)columnson useTable (options)dataon useTable (options)getRowIdon useTable (options)rowHeaderon useTable (options)initialStateon useTable (options)headeron Table.SortButton
Information: Did you know?
The default TanStack sort compares character codes. In Swedish it puts å, ä and ö in the wrong place. Use createLocaleSortFn(locale), as here.
Searching a list of cases
A case worker looks for one case in a long list. A search box above the table filters the rows as they type, and the table says how many rows match, such as “3 rows.”, once they stop typing. See Announcements.
| Name | Case number | Handler |
|---|---|---|
| Anna Svensson | BN 2026-0142 | Karin Lund |
| Åsa Öberg | BN 2026-0157 | Johan Ek |
| Erik Lindqvist | BN 2026-0163 | Karin Lund |
| Zacharias Nilsson | BN 2026-0171 | Maria Berg |
| Ärlig Holm | BN 2026-0188 | Johan Ek |
import {
Field,
Table,
TextInput,
columnFilteringFeature,
createColumnHelper,
createFilteredRowModel,
globalFilteringFeature,
tableFeatures,
useTable,
} from '@kvirn-ui/react'
import { useMemo } from 'react'
import { cases } from './cases.ts'
import type { CaseRecord } from './cases.ts'
import { useTableTexts } from './texts.ts'
const features = tableFeatures({
columnFilteringFeature,
globalFilteringFeature,
filteredRowModel: createFilteredRowModel(),
})
export function FilterableCases() {
const { texts } = useTableTexts()
const columns = useMemo(() => {
const column = createColumnHelper<typeof features, CaseRecord>()
return column.columns([
column.accessor('name', { header: texts.name }),
column.accessor('caseNumber', { header: texts.caseNumber }),
column.accessor('handler', { header: texts.handler }),
])
}, [texts])
const list = useTable({
features,
columns,
data: cases,
getRowId: (record) => record.id,
rowHeader: 'name',
})
return (
<>
<Field.Root>
<Field.Label>{texts.searchCases}</Field.Label>
<TextInput type="search" onValueChange={(value) => list.table.setGlobalFilter(value)} />
</Field.Root>
<Table.ScrollRegion table={list}>
<Table.Root table={list}>
<Table.Caption>{texts.casesCaption}</Table.Caption>
<Table.Head>
{list.table.getHeaderGroups().map((headerGroup) => (
<Table.Row key={headerGroup.id} headerGroup={headerGroup}>
{headerGroup.headers.map((header) => (
<Table.ColumnHeader key={header.id} header={header} />
))}
</Table.Row>
))}
</Table.Head>
<Table.Body>
{(row) => (
<Table.Row key={row.id} row={row}>
{row.getAllCells().map((cell) => (
<Table.Cell key={cell.id} cell={cell} />
))}
</Table.Row>
)}
</Table.Body>
<Table.Empty>{texts.noMatchingCases}</Table.Empty>
</Table.Root>
</Table.ScrollRegion>
</>
)
}Props in this example:
Rows the user can select
Put a checkbox in the first cell for bulk actions. Each checkbox is named by its row, so “Select Anna Svensson” is different from “Select Åsa Öberg”, and the header checkbox selects them all.
| Anna Svensson | BN 2026-0142 | 4,200 | |
|---|---|---|---|
| Åsa Öberg | BN 2026-0157 | 1,850 | |
| Erik Lindqvist | BN 2026-0163 | 12,500 | |
| Zacharias Nilsson | BN 2026-0171 | 960 | |
| Ärlig Holm | BN 2026-0188 | 7,300 |
import {
Table,
createColumnHelper,
createLocaleSortFn,
createSortedRowModel,
rowSelectionFeature,
rowSortingFeature,
tableFeatures,
useFormat,
useTable,
} from '@kvirn-ui/react'
import { useMemo } from 'react'
import { cases } from './cases.ts'
import type { CaseRecord } from './cases.ts'
import { useTableTexts } from './texts.ts'
const features = tableFeatures({
rowSortingFeature,
sortedRowModel: createSortedRowModel(),
sortFns: { locale: createLocaleSortFn('sv') },
rowSelectionFeature,
})
export function SelectableCases() {
const { texts } = useTableTexts()
const format = useFormat()
const columns = useMemo(() => {
const column = createColumnHelper<typeof features, CaseRecord>()
return column.columns([
column.accessor('name', { header: texts.name, sortFn: 'locale' }),
column.accessor('caseNumber', { header: texts.caseNumber }),
column.accessor('amount', {
header: texts.amount,
cell: (info) => format.number(info.getValue()),
}),
])
}, [texts, format])
const list = useTable({
features,
columns,
data: cases,
getRowId: (record) => record.id,
rowHeader: 'name',
initialState: { rowSelection: { c1: true, c3: true } },
})
return (
<Table.ScrollRegion table={list}>
<Table.Root table={list}>
<Table.Caption>{texts.casesCaption}</Table.Caption>
<Table.Head>
{list.table.getHeaderGroups().map((headerGroup) => (
<Table.Row key={headerGroup.id} headerGroup={headerGroup}>
<Table.ColumnHeader>
<Table.SelectAllCheckbox />
</Table.ColumnHeader>
{headerGroup.headers.map((header) => (
<Table.ColumnHeader
key={header.id}
header={header}
className={
header.column.id === 'amount' ? 'kv-table-column-header--numeric' : undefined
}
>
{header.column.getCanSort() ? <Table.SortButton header={header} /> : null}
</Table.ColumnHeader>
))}
</Table.Row>
))}
</Table.Head>
<Table.Body>
{(row) => (
<Table.Row key={row.id} row={row}>
<Table.Cell>
<Table.SelectCheckbox row={row} />
</Table.Cell>
{row.getAllCells().map((cell) => (
<Table.Cell
key={cell.id}
cell={cell}
className={cell.column.id === 'amount' ? 'kv-table-cell--numeric' : undefined}
/>
))}
</Table.Row>
)}
</Table.Body>
<Table.Empty />
</Table.Root>
</Table.ScrollRegion>
)
}Props in this example:
Information: Did you know?
The header checkbox selects every row of the table, including rows on other pages. With pagination, say so in the table’s description, or change the checkbox’s name with messages.selectAllRows.
Details under a row
Show the rest of a case under its row without leaving the table. The button says “Details” and names its row, and the detail is the next row, spanning every column.
| Details | Name | Case number | Amount (SEK) |
|---|---|---|---|
| Anna Svensson | BN 2026-0142 | 4,200 | |
| Åsa Öberg | BN 2026-0157 | 1,850 | |
| |||
| Erik Lindqvist | BN 2026-0163 | 12,500 | |
| Zacharias Nilsson | BN 2026-0171 | 960 | |
| Ärlig Holm | BN 2026-0188 | 7,300 | |
import {
Table,
createColumnHelper,
createExpandedRowModel,
rowExpandingFeature,
tableFeatures,
useFormat,
useTable,
} from '@kvirn-ui/react'
import { useMemo } from 'react'
import { cases } from './cases.ts'
import type { CaseRecord } from './cases.ts'
import { useTableTexts } from './texts.ts'
const features = tableFeatures({
rowExpandingFeature,
expandedRowModel: createExpandedRowModel(),
})
export function ExpandableCases() {
const { texts } = useTableTexts()
const format = useFormat()
const columns = useMemo(() => {
const column = createColumnHelper<typeof features, CaseRecord>()
return column.columns([
column.accessor('name', { header: texts.name }),
column.accessor('caseNumber', { header: texts.caseNumber }),
column.accessor('amount', {
header: texts.amount,
cell: (info) => format.number(info.getValue()),
}),
])
}, [texts, format])
const list = useTable({
features,
columns,
data: cases,
getRowId: (record) => record.id,
getRowCanExpand: () => true,
rowHeader: 'name',
initialState: { expanded: { c2: true } },
})
return (
<Table.ScrollRegion table={list}>
<Table.Root table={list}>
<Table.Caption>{texts.casesCaption}</Table.Caption>
<Table.Head>
{list.table.getHeaderGroups().map((headerGroup) => (
<Table.Row key={headerGroup.id} headerGroup={headerGroup}>
<Table.ColumnHeader>
<span className="kv-table-visually-hidden">{list.expandButtonText}</span>
</Table.ColumnHeader>
{headerGroup.headers.map((header) => (
<Table.ColumnHeader
key={header.id}
header={header}
className={
header.column.id === 'amount' ? 'kv-table-column-header--numeric' : undefined
}
/>
))}
</Table.Row>
))}
</Table.Head>
<Table.Body>
{(row) => {
const record = list.table.getRow(row.id).original
return (
<>
<Table.Row key={row.id} row={row}>
<Table.Cell>
<Table.ExpandButton row={row} />
</Table.Cell>
{row.getAllCells().map((cell) => (
<Table.Cell
key={cell.id}
cell={cell}
className={cell.column.id === 'amount' ? 'kv-table-cell--numeric' : undefined}
/>
))}
</Table.Row>
<Table.DetailRow row={row}>
<dl>
<dt>{texts.handlerLabel}</dt>
<dd>{record.handler}</dd>
<dt>{texts.decisionLabel}</dt>
<dd>{texts.decisions[record.decision]}</dd>
</dl>
</Table.DetailRow>
</>
)
}}
</Table.Body>
<Table.Empty />
</Table.Root>
</Table.ScrollRegion>
)
}Props in this example:
Warning: Don't forget
Put the button’s text in the expand column’s header, hidden from sight, as in the code. Without it that header cell is empty, and a screen reader user can’t tell what the column is (1.3.1 Info and Relationships).
When there are no rows
An empty table keeps its head and says why it is empty and what to do next, in one row that spans the columns. Table.Empty renders only when there are no rows.
| Name | Case number |
|---|---|
| You have no open cases. New applications show up here when you send them. | |
import { Table, createColumnHelper, tableFeatures, useTable } from '@kvirn-ui/react'
import { useMemo } from 'react'
import type { CaseRecord } from './cases.ts'
import { useTableTexts } from './texts.ts'
const features = tableFeatures({})
export function EmptyCases() {
const { texts } = useTableTexts()
const columns = useMemo(() => {
const column = createColumnHelper<typeof features, CaseRecord>()
return column.columns([
column.accessor('name', { header: texts.name }),
column.accessor('caseNumber', { header: texts.caseNumber }),
])
}, [texts])
const list = useTable({
features,
columns,
data: [],
getRowId: (record) => record.id,
rowHeader: 'name',
})
return (
<Table.ScrollRegion table={list}>
<Table.Root table={list}>
<Table.Caption>{texts.casesCaption}</Table.Caption>
<Table.Head>
{list.table.getHeaderGroups().map((headerGroup) => (
<Table.Row key={headerGroup.id} headerGroup={headerGroup}>
{headerGroup.headers.map((header) => (
<Table.ColumnHeader key={header.id} header={header} />
))}
</Table.Row>
))}
</Table.Head>
<Table.Body>{() => null}</Table.Body>
<Table.Empty>{texts.emptyCases}</Table.Empty>
</Table.Root>
</Table.ScrollRegion>
)
}Props in this example:
childrenon Table.Empty
A table with 2,000 rows
When the user needs the whole list and cannot page through it, render only the rows near the scroll position. The table still says how big it is, and the row that has focus stays in the page.
| Anna Svensson 1 | BN 2026-1000 | 500 |
|---|---|---|
| Åsa Öberg 2 | BN 2026-1001 | 1,437 |
| Erik Lindqvist 3 | BN 2026-1002 | 2,374 |
| Zacharias Nilsson 4 | BN 2026-1003 | 3,311 |
| Ärlig Holm 5 | BN 2026-1004 | 4,248 |
| Anna Svensson 6 | BN 2026-1005 | 5,185 |
| Åsa Öberg 7 | BN 2026-1006 | 6,122 |
| Erik Lindqvist 8 | BN 2026-1007 | 7,059 |
| Zacharias Nilsson 9 | BN 2026-1008 | 7,996 |
| Ärlig Holm 10 | BN 2026-1009 | 8,933 |
| Anna Svensson 11 | BN 2026-1010 | 9,870 |
| Åsa Öberg 12 | BN 2026-1011 | 10,807 |
| Erik Lindqvist 13 | BN 2026-1012 | 11,744 |
| Zacharias Nilsson 14 | BN 2026-1013 | 12,681 |
| Ärlig Holm 15 | BN 2026-1014 | 13,618 |
| Anna Svensson 16 | BN 2026-1015 | 14,555 |
| Åsa Öberg 17 | BN 2026-1016 | 15,492 |
| Erik Lindqvist 18 | BN 2026-1017 | 16,429 |
import {
Table,
columnSizingFeature,
createColumnHelper,
createLocaleSortFn,
createSortedRowModel,
rowSortingFeature,
tableFeatures,
useFormat,
useTable,
} from '@kvirn-ui/react'
import { useMemo } from 'react'
import { manyCases } from './cases.ts'
import type { CaseRecord } from './cases.ts'
import { useTableTexts } from './texts.ts'
const features = tableFeatures({
rowSortingFeature,
sortedRowModel: createSortedRowModel(),
sortFns: { locale: createLocaleSortFn('sv') },
columnSizingFeature,
})
const data = manyCases(2000)
export function LargeTable() {
const { texts } = useTableTexts()
const format = useFormat()
const columns = useMemo(() => {
const column = createColumnHelper<typeof features, CaseRecord>()
return column.columns([
column.accessor('name', { header: texts.name, sortFn: 'locale', size: 240 }),
column.accessor('caseNumber', { header: texts.caseNumber, size: 180 }),
column.accessor('amount', {
header: texts.amount,
size: 140,
cell: (info) => format.number(info.getValue()),
}),
])
}, [texts, format])
const list = useTable({
features,
columns,
data,
getRowId: (record) => record.id,
rowHeader: 'name',
virtualize: { estimateSize: 40, overscan: 8 },
})
return (
<Table.ScrollRegion table={list} style={{ maxBlockSize: '20rem' }}>
<Table.Root table={list}>
<Table.Caption>{texts.allCases}</Table.Caption>
<Table.Head>
{list.table.getHeaderGroups().map((headerGroup) => (
<Table.Row key={headerGroup.id} headerGroup={headerGroup}>
{headerGroup.headers.map((header) => (
<Table.ColumnHeader
key={header.id}
header={header}
className={
header.column.id === 'amount' ? 'kv-table-column-header--numeric' : undefined
}
>
{header.column.getCanSort() ? <Table.SortButton header={header} /> : null}
</Table.ColumnHeader>
))}
</Table.Row>
))}
</Table.Head>
<Table.Body>
{(row) => (
<Table.Row key={row.id} row={row}>
{row.getAllCells().map((cell) => (
<Table.Cell
key={cell.id}
cell={cell}
className={cell.column.id === 'amount' ? 'kv-table-cell--numeric' : undefined}
/>
))}
</Table.Row>
)}
</Table.Body>
</Table.Root>
</Table.ScrollRegion>
)
}Props in this example:
virtualizeon useTable (options)
Information: Implement like this
Prefer pages with a status such as “Rows 21–40 of 312”, or a filter. If you virtualize, give the scroll region a height and a way to search.
Accessibility#
What it does for you#
- APG pattern: Table and the Sortable Table example. Not the Grid pattern: a read-only data table keeps the screen reader's table navigation, and the keys are the ones a web page already has.
- Deviations: none from APG. It is a native
<table>with norole="grid". - Native elements used:
<table>,<caption>,<thead>,<tbody>,<tfoot>,<tr>,<th scope>,<td>,<button>(sort and expand),<input type="checkbox">(selection),<div>that is arole="region"while it scrolls, or always withregion="always"(scroll region).
A Table shows data in rows and columns. It renders a native <table>, so a screen reader reads its headers, rows and columns and says where you are. With useTable it sorts one column at a time, selects rows, expands a row to show its details, filters and paginates through TanStack Table, and can render only the rows near the scroll position. Without useTable every part is the plain native element, so a small static table needs none of it.
| Part | Element / role | ARIA / state | Notes |
|---|---|---|---|
| Table.Root | <table> (implicit role table) | aria-busy="true" while isLoading. Virtualized: aria-rowcount (header rows, every row of the data and the rows of Table.Foot). data-busy, data-virtualized | Class kv-table. Never display other than native, so no role is ever needed on a table element. Named by Table.Caption or aria-labelledby: without one, a development warning |
| Table.ScrollRegion | <div>, <div role="region"> while it scrolls or region="always" | role="region" and aria-labelledby the caption's id (only while the table has a Table.Caption) only while the region is one: it overflows, or region="always". tabindex="0" and data-overflowing only while the table overflows, in both modes. Not a region (the default, nothing overflows): no role, no name, no tabindex | Classes kv-scroll-region kv-table-scroll-region. The virtualizer's scroll element. Sets a CSS variable with the measured height of the table's <thead> (the theme uses it as scroll padding), with table and without it, so a static table whose head the theme makes sticky also leaves a focused control clear. Prop region: 'overflow' (default) or 'always'. Your own aria-labelledby or aria-label replaces the caption's |
| Table.Caption | <caption> | none | Class kv-table-caption. The table's name, and the region's |
| Table.Head, Body, Foot | <thead>, <tbody>, <tfoot> | none | Classes kv-table-head, kv-table-body, kv-table-foot. Virtualized: the head stays in the DOM and is measured, so the theme can make it sticky |
| Table.Row | <tr> | virtualized: aria-rowindex: a body row by its place in the data, a header row by its headerGroup, or by its place in the head without one, a footer row by its place in the foot after every other row. data-selected, data-expanded. Never aria-selected (not allowed on a row in a table) | Class kv-table-row. data-index when virtualized |
| Table.ColumnHeader | <th scope="col"> | aria-sort="ascending|descending" on the sorted column only, with data-sort. A colSpan above 1 is scope="colgroup" | Class kv-table-column-header. With header it renders the column's header template when it has no children. Virtualized: an inline inline-size from the column size, which a fixed layout reads from the head. A quantity column adds kv-table-column-header--numeric |
| Table.RowHeader, Cell | <th scope="row">, <td> | none | Classes kv-table-row-header, kv-table-cell. With cell, the rowHeader column is a <th scope="row">, and the cell template is rendered when there are no children. A quantity adds kv-table-cell--numeric (or kv-table-row-header--numeric) |
| Table.SortButton | <button type="button"> in the header | data-sort. The state is aria-sort on the header, never the icon | Class kv-table-sort-button. Its name is the header text. The icon is an svg (kv-table-sort-icon, aria-hidden) drawn by the component: two chevrons while sortable, one up chevron ascending, one down chevron descending, so the states differ in shape |
| Table.SelectCheckbox | <input type="checkbox"> | named "Select" then the row header cell: aria-labelledby = its own id then the row header's id, with aria-label "Select". Without a rowHeader: aria-label "Select row 3" | Classes kv-checkbox kv-table-select-checkbox (a Checkbox: the box is at least 24 by 24 CSS pixels). Native checked. Disabled when the row can't be selected |
| Table.SelectAllCheckbox | <input type="checkbox"> | aria-label "Select all rows". indeterminate (the DOM property, exposed as mixed) while some rows are selected | Classes kv-checkbox kv-table-select-checkbox. It selects every row of the table, not only the rows of one page |
| Table.ExpandButton | <button type="button"> | aria-expanded. aria-controls the detail row while it is shown. Named by its visible text and the row header: aria-labelledby = its own id then the row header's id ("Details Anna Svensson"). With no rowHeader: aria-label "Details row 3", which starts with the visible text. Children of your own, or an aria-label or aria-labelledby of your own, replace it | Class kv-table-expand-button. Visible text "Details" and a chevron (svg.kv-table-expand-icon, aria-hidden): down while hidden, up while shown, never rotated. The name is the same open and closed. The expand column's header holds the same text, visually hidden |
| Table.DetailRow | <tr> with one <td> that spans every column | data-expanded | Class kv-table-detail-row. Rendered only while the row is expanded. No aria-level: it isn't allowed outside a tree grid |
| Table.Empty | <tbody> with one <tr> and one <td> spanning every column | none | Class kv-table-empty. Shown only when the row model is empty. While the table loads and has no rows it says "Loading rows." instead of the empty text, so it never claims there is nothing |
| Spacer rows | <tr aria-hidden="true"> with one <td> | aria-hidden | Class kv-table-spacer. Virtualized only: one for each gap of unrendered rows. The block size is inline: the one thing virtualization can't work without |
useTable | the same attributes, for your own elements | tableProps, captionProps, scrollRegionProps, headProps, bodyProps, getColumnHeaderProps, getSortButtonProps, getRowProps, getCellProps, getSelectCheckboxProps, getSelectAllCheckboxProps, getExpandButtonProps, getDetailRowProps, emptyProps, rows | Options: TanStack Table's, plus rowHeader, virtualize, isLoading, region and messages. getScrollRegionProps(region) is scrollRegionProps for another region. Spread each on its element |
Rules, each proved by a test in the component's test file:
- Native semantics first. A table is
<table>, with<caption>,<th scope>and<td>. Nothing changes thedisplayof a table element, because some browsers then drop the table semantics. There is norole="table",roworcellanywhere. - A name is required.
Table.Caption, oraria-labelledbyon the Root pointing at a visible heading. A table with neither warns once in development. While the scroll region is a region (it scrolls, orregion="always") it is named by the caption througharia-labelledby, so the table and its region are one thing to a user. A table with no caption names the region witharia-labelledbyoraria-labelonTable.ScrollRegion: a region with no name is an unlabelled landmark (4.1.2 Name, Role, Value, A). aria-sortis on the sorted column only. Not on the other sortable columns (noneis left out), as the APG example. With one column sorted at a time, there is never a question which one is primary.- One column at a time.
enableMultiSortis alwaysfalse: multi-sort needs Shift+click, a key the Table pattern doesn't define. Passing it is a type error. A Shift+click is a plain click. - Sorting is announced, because
aria-sortchanges aren't reliably read: "Sorted by Name, ascending.", "Sorted by Name, descending." or "No longer sorted by Name." (the English texts; each language has its own). The column is the header text when it is a string, and the sort button's text otherwise. The cycle is TanStack's: the first direction for the column's data, the other, then none. - The locale decides the order.
createLocaleSortFn(locale)sorts withIntl.Collator, so å, ä and ö come after z in Swedish, Finnish and Norwegian. The default TanStack sort functions compare code points and get it wrong. - Row checkboxes are named by their row. "Select Anna Svensson": the checkbox is named by its own
aria-label("Select") and the row header cell, througharia-labelledby. Every checkbox has a different name, so a screen reader user hears which row, and a voice user can say "click select Anna Svensson". Without arowHeaderthe name is "Select row 3", from the row's place in the row model. - Selected rows have
data-selected, neveraria-selected. ARIA 1.2 allowsaria-selectedon a row only in a grid or a tree grid. The state a screen reader reads is the row's checkbox. - Select-all is indeterminate while some rows are selected, and toggling it announces the count: "12 rows selected."
- Expanding follows the disclosure pattern. The button has
aria-expandedandaria-controls(the detail row while it is shown). Its visible text "Details" and the row header name it ("Details Anna Svensson"), so every button in the table has its own name and the visible text comes first (2.5.3 Label in Name, A). With norowHeaderthe name istable.rowDetailsNumber("Details row 3"), which also starts with the visible text. The name doesn't change: onlyaria-expandeddoes. The detail is the next row, with one cell that spans every column. The expand column has a header too, with the same text visually hidden, so it isn't an empty header. - States.
isLoadingsetsaria-busy="true"anddata-busyand announces "Loading rows." An empty row model showsTable.Empty("No rows to show."). While loading with no rows yet, that row says "Loading rows." instead, so it never says there is nothing while rows are on their way. A filter change announces the number of rows ("3 rows."), after 500 ms without a change. - Spacer and detail rows span what is drawn, which includes cells that aren't columns (a checkbox cell). The column count is read from the header row once it is in the DOM.
- Virtualization is opt-in and never changes keys. With
virtualize, the rows outside the window are replaced byaria-hiddenspacer rows. The table hasaria-rowcount(the header rows, every row of the data and the rows ofTable.Foot) and each rendered row hasaria-rowindex, so a screen reader knows how big the table is and where a row is. A header row without aheaderGroup, and a footer row, are numbered by their place in their section (sectionRowIndex), read after each commit. The row that holds focus stays rendered while it is scrolled away (focusinon the body). The scroll region measures the sticky header's height and the theme uses it as scroll padding, so a focused row is not left under the header (2.4.11 Focus Not Obscured (Minimum), AA). A region withouttablemeasures its own<thead>the same way, and finds a head that is added after the region has mounted. A virtualized table also tells its virtualizer how far the first row is from the start of the region (the caption and the head above it), so the window is right at every scroll position.table-layout: fixedcomes from the theme, because spacer rows need columns that don't jump. - Virtualization with expanding rows is not supported: a development warning, and every row is rendered.
- Every part merges the consumer's class names, handlers and refs with its own. For another element, spread the
useTableprop objects on your own. - Dev warnings: no name, a function as the Body's children with no
tableon the Root, a select checkbox with norowSelectionFeature, virtualize withrowExpandingFeature, a scroll region that is a region and has no name, and a missing Announcer when something has to be announced.
What you need to do#
- Name the table with
Table.Captionoraria-labelledby, and say what the data is. - Give the expand column a header with the button text visually hidden:
<span className="kv-table-visually-hidden">{cases.expandButtonText}</span>in aTable.ColumnHeader. Without a select-all checkbox, the select column's header needs hidden text too. - Align quantities to the end with
kv-table-column-header--numericon the header andkv-table-cell--numericon each cell of the column (amounts, counts, percentages). Identifiers and dates stay at the start. - Choose a
rowHeader(the name or case number that identifies the row). It names the row's checkbox and expand button, and screen readers read it as the row's title. Keep one link per row, in the row header, and put other actions in a menu: many interactive cells mean many Tab stops. - Give the sort button's column a readable
header. A header template that returns something other than text is announced from the sort button's text. - Say what "all rows" means. The select-all checkbox selects every row of the table, including rows on other pages. With pagination, say so in the table's description, or override
messages.selectAllRows. - Replace the empty text with something useful: why there are no rows, and what to do next.
- Large data: paginate or filter first, virtualize last. Unrendered rows can't be found with find-in-page, aren't printed and are out of reach of screen-reader browse mode. If you virtualize, give the scroll region a height, keep rows to one measured size where you can, and provide a way to find a row by search or filter.
- Narrow screens. Put the table in
Table.ScrollRegion: when the table scrolls, the region is a named, focusableregion, and when it fits, a plain<div>. Addregion="always"to make it a named region either way. Name it: aTable.Captionwithtable, oraria-labelledbyoraria-labelon the region when the table has no caption. A data table that needs two dimensions is exempt from reflow (1.4.10 Reflow, AA), but must be reachable and scrollable. Don't turn rows into cards withdisplay: block: it drops the table semantics. - Translate your own text: the caption, the headers and the cells.
- A moving loading bar needs a stop control (2.2.2 Pause, Stop, Hide, A). 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 (2.2.2). An indicator that is the only content during a wait where nothing else can be done is exempt.
prefers-reduced-motionalone is not that control. Moving indicators and WCAG 2.2.2. - Provide the Announcer (
KvirnProvider). Without one, nothing is announced.
Warning: Don't forget
Give every table a caption that says what the data is. Without a name, a screen reader user can’t tell the tables on a page apart (1.3.1 Info and Relationships). A development warning says so.
Visual and modes#
- Focus indicator: the default theme draws the focus ring of every control in the table, and of the scroll region. It leaves room for the sticky header (see Focus management).
- Target size: sort buttons and expand buttons are larger than 24 by 24 CSS pixels in both densities. Checkboxes are 24 by 24, the Checkbox's own size, and the cell's padding keeps neighbouring targets apart (2.5.8 Target Size (Minimum), AA).
- The sort icon is not the state.
aria-sort,data-sortand the icon's shape carry it, never colour alone (1.4.1 Use of Color, A). - forced-colors: the header's edge is a border in the system's text colour, never a shadow or a background alone. A selected row loses its fill, and its checked checkbox shows the state. The forced-colours sweep asserts a drawn boundary or distinct text on every focusable part and a focus ring on the focused one. The selected row's lost fill and the header's border colour are not asserted by it.
- reduced-motion: sorting and expanding don't animate. While
isLoading, the loading bar moves under no preference and rests underprefers-reduced-motion(see Consumer responsibilities, 2.2.2). - Reflow and zoom: the table scrolls inside its named region (the region is named while it scrolls) at a width of 320 CSS pixels and at 400% zoom (1.4.10 Reflow, AA). Cells have no fixed height, so text spacing doesn't clip them (1.4.12 Text Spacing, AA). The reflow sweep proves the scroll region itself fits 320 CSS pixels, with Finnish text, and that the table scrolls inside it. 400% zoom is not asserted by a test, and the text-spacing sweep fails on a cell that clips its text.
- RTL: logical properties, so the columns and the scroll direction mirror. The sort icon doesn't flip: up and down aren't directions of the reading order.
Warning: Don't forget
While isLoading is on, the table head shows a bar that keeps moving. If it can move for more than 5 seconds next to other content, the page needs a visible control that stops or hides it (2.2.2 Pause, Stop, Hide). The reduced motion setting alone is not that control. See Moving indicators and WCAG 2.2.2.
Focus management#
- Initial focus: none. The table never moves focus.
- Trap: no. Tab always leaves the table.
- Restore to: n/a. Sorting, selecting and expanding keep focus on the button or checkbox that was pressed. Sorting reorders the rows under it, and focus stays on the sort button.
- A focused row stays mounted while virtualized. The body tracks
focusinandfocusout, and the row that holds focus is a required index of the virtualizer, so it is rendered wherever the table is scrolled. Focus never falls tobodybecause a row was unmounted. - Never obscured by: the sticky header.
Table.ScrollRegionmeasures the header's height, with or withoutuseTable, and measures it again when the header wraps. The theme uses it as scroll padding, so Tab and a scroll to a row are meant to leave the focused control clear (2.4.11 Focus Not Obscured (Minimum), AA). - The scroll region is a Tab stop only while it scrolls, so a keyboard user can reach and scroll a table that overflows (2.1.1 Keyboard, A), and meets no empty stop when it doesn't. This holds with
region="always"too: the option adds the role and the name, never a tab stop. If the table stops overflowing while the region itself has focus, it keeps itstabindex, and its role, until focus leaves, so focus is never dropped to the page. - The scroll region is a named region only while it scrolls, by default. A table that fits is a plain
<div>with no role, no name and notabindex, so a page with several short tables doesn't list an empty landmark for each (1.3.1 Info and Relationships, A). The role is set after the first measurement, so the server render and the first client render are the same markup (the plain<div>).region="always"(onTable.ScrollRegionoruseTable) makes it a named region from the first render, whether it scrolls or not, for a page that wants a table to be a landmark users can jump to. - Virtualized tables skip what isn't rendered. Tab goes through the rendered rows. A row outside the window and its overscan has no controls in the DOM until it is scrolled to.
Warning: Don't forget
Put every table that can be wider than the screen in Table.ScrollRegion, and name it. The table then scrolls sideways inside the region at 320 CSS pixels, and a keyboard user can reach and scroll it (1.4.10 Reflow, 2.1.1 Keyboard).
WCAG success criteria#
| SC | Name | How |
|---|---|---|
| 1.3.1 | Info and Relationships (A) | A native table, caption, <th scope>, aria-sort, and names for every checkbox and button |
| 1.3.2 | Meaningful Sequence (A) | The DOM order is the reading order. Spacer rows are hidden |
| 1.4.1 | Use of Color (A) | Sort state, selection and expansion are in attributes, text and shape, never colour alone |
| 1.4.10 | Reflow (AA) | A data table is exempt, and it scrolls inside a focusable region, named while it scrolls |
| 1.4.11 | Non-text Contrast (AA) | The default theme's focus ring and control borders, checkbox included, are held to 3:1 by the theme's contrast check |
| 1.4.12 | Text Spacing (AA) | Cells have no fixed height, so spacing doesn't clip text (the text-spacing sweep checks it) |
| 2.1.1 | Keyboard (A) | Every control is a native button or checkbox. The scroll region is focusable while it scrolls |
| 2.4.3 | Focus Order (A) | Tab follows the reading order. A focused row stays rendered |
| 2.4.7 | Focus Visible (AA) | Every control and the scroll region show focus |
| 2.4.11 | Focus Not Obscured (Minimum) (AA) | The scroll padding is the sticky header's height (no automated test measures it) |
| 2.5.3 | Label in Name (A) | Visible text names its button: the header text, and the visible text of an expand button |
| 2.5.8 | Target Size (Minimum) (AA) | Checkboxes are 24 by 24 CSS pixels, sort and expand buttons larger |
| 3.2.2 | On Input (A) | Sorting, selecting or expanding never changes context: focus stays on the control and nothing navigates or opens |
| 4.1.2 | Name, Role, Value (A) | Native roles. Checkboxes, sort buttons and expand buttons have names and states |
| 4.1.3 | Status Messages (AA) | Sort, select-all count, loading and filtered row count are announced politely |
Keyboard#
- Focus
- native
- Selection follows focus
- n/a
- Arrows wrap
- n/a
- Shortcuts
- none
| Key | Where | What happens |
|---|---|---|
| Tab | before the table | Moves to the scroll region when the table overflows, and otherwise to the first control in the table Test: table.test.tsx › Tab focuses the scroll region when the table overflows, table.test.tsx › Tab skips the scroll region when nothing scrolls |
| Tab | in the table | Moves through the sort buttons, checkboxes, expand buttons and links in reading order. Header cells, rows and cells are not stops Test: table.test.tsx › Tab moves through the controls in reading order |
| Shift+Tab | in the table | Moves back through the same controls, and from the first one to the scroll region or the element before the table Test: table.test.tsx › Shift+Tab moves back through the controls |
| Enter | on a sort button | Sorts by that column, or changes its direction, and announces it Test: table.test.tsx › Enter on a sort button sorts the column and announces it |
| Space | on a sort button | Same as Enter Test: table.test.tsx › Space on a sort button sorts the column |
| Space | on a row checkbox | Selects or deselects the row Test: table.test.tsx › Space on a row checkbox selects the row |
| Space | on the select-all checkbox | Selects or deselects every row, and announces the count Test: table.test.tsx › Space on select-all selects every row and announces the count |
| Enter | on an expand button | Shows the row's details Test: table.test.tsx › Enter on an expand button shows the details |
| Space | on an expand button | Hides the row's details again Test: table.test.tsx › Space on an expand button hides the details |
| Tab | on a control in a row of a virtualized table | Moves to the next control, which is in the rows in view and never body. The row that holds focus stays rendered, wherever the table is scrolled to, until focus leaves it; Shift+Tab then goes to the previous control that is renderedTest: table.test.tsx › A focused row stays rendered while the virtualized table scrolls |
| ArrowDown | on the focused scroll region | Scrolls the table down (native) Test: table.test.tsx › ArrowDown scrolls the focused scroll region |
| ArrowRight | on the focused scroll region | Scrolls the table sideways (native, flips in RTL) Test: table.test.tsx › ArrowRight scrolls the focused scroll region sideways, table.test.tsx › ArrowLeft scrolls the scroll region sideways in right-to-left |
| PageDown | on the focused scroll region | Scrolls the table a page (native) Test: table.test.tsx › PageDown scrolls the focused scroll region a page |
| Escape / any character | anywhere in the table | Nothing. There is no type-ahead and no shortcut Test: table.test.tsx › Escape and letters do nothing |
Announcements#
Table 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 |
|---|---|---|---|
| A sort button sorts a column ascending | Sorted by Name, ascending. | table.sortedAscending | Polite |
| A sort button sorts a column descending | Sorted by Name, descending. | table.sortedDescending | Polite |
| A sort button removes the sort | No longer sorted by Name. | table.sortCleared | Polite |
| The select-all checkbox changes the selection | 12 rows selected. | table.selectedCount | Polite |
| A filter changed the rows (after 500 ms) | 3 rows. | table.rowCount | Polite |
isLoading became true | Loading rows. | table.loading | Polite |
Change the text#
For your whole app, pass messages to KvirnProvider. For one Table, pass its messages prop.
<KvirnProvider messages={{ table: { sortedAscending: 'Sorted by Name, ascending.' } }}>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 { Table, useTable, tableFeatures, createColumnHelper } from '@kvirn-ui/react'Table.Root
Renders <table>, which has the role table natively. It takes every attribute of a <table> and passes ref to it. Name it with a Table.Caption, or aria-labelledby. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
table | UseTableResult | – | The result of useTable(). Without it the part is the plain native element with its class, so a small static table needs no TanStack Table. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-table | always | The part class. |
aria-busy | "true" or absent | Rows are loading (isLoading). |
data-busy | present or absent | Rows are loading (isLoading). |
data-virtualized | present or absent | virtualize is on. |
aria-rowcount | a number | Virtualized only: the header rows, every row of the data and the rows of Table.Foot. |
Table.ScrollRegion
Renders <div> around the table. While the table scrolls, it is a named region and a Tab stop, so a keyboard user can scroll the table. When the table fits, it is a plain <div>. With region="always" it is a named region even when nothing scrolls, but it is a Tab stop only while the table scrolls. It is also the virtualizer’s scroll element.
| Prop | Type | Default | Description |
|---|---|---|---|
table | UseTableResult | – | The same useTable() result as the Root: the region is named by the table’s caption and is the virtualizer’s scroll element. |
region | 'overflow' | 'always' | 'overflow' | When the region is a named region landmark: only while the table scrolls, or always. It is a Tab stop only while it scrolls. With table, this wins over the region option of useTable. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-scroll-region kv-table-scroll-region | always | The part classes. |
role | "region" or absent | A named region while the table scrolls, or always with region="always". |
aria-labelledby | the caption’s id | Names the region, while it is one and the table has a caption. Yours replaces it. |
tabindex | "0" or absent | A Tab stop only while the table scrolls, so a keyboard user can scroll it. |
data-overflowing | present or absent | The table scrolls. |
--kv-table-head-block-size | a length in px | Set on the region: the height of the head, which the theme uses as scroll padding. |
Table.Caption, Table.Head, Table.Foot, Table.RowHeader
Renders <caption>, <thead>, <tfoot> and <th scope="row">. Each takes every attribute of its element and passes ref to it.
| Class or attribute | Values | Meaning |
|---|---|---|
kv-table-caption | always | Table.Caption: the table’s name. |
kv-table-head | always | Table.Head. |
kv-table-foot | always | Table.Foot. |
kv-table-row-header | always | Table.RowHeader: renders <th scope="row">. |
Table.Body
Renders <tbody>. It takes every attribute of a <tbody> and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | ((row, index) => ReactNode) | – | Your own rows, or a function that renders one Row per row of the row model. The function needs table on the Root. Virtualized, only the rows near the scroll position are rendered, with spacer rows between. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-table-body | always | The part class. |
kv-table-spacer | on a row you do not render | Virtualized only: a row with aria-hidden="true" stands in for each gap of unrendered rows. |
Table.Row
Renders <tr>. It takes every attribute of a <tr> and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
row | Row | – | The row of the row model: sets data-selected, data-expanded and, virtualized, aria-rowindex. |
headerGroup | HeaderGroup | – | In the head: the header group the row shows, for aria-rowindex when virtualized. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-table-row | always | The part class. |
data-selected | present or absent | The row is selected. |
data-expanded | present or absent | The row’s details are shown. |
data-index | a number | Virtualized only: the row’s place in the data. |
aria-rowindex | a number | Virtualized only: the row’s number, counting the header rows. |
Table.ColumnHeader
Renders <th scope="col">. It takes every attribute of a <th> and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
header | Header | – | The header from table.getHeaderGroups(): sets colSpan and aria-sort, and without children renders the column’s header template. Leave it out for a column you add yourself. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-table-column-header | always | The part class. |
kv-table-column-header--numeric | class you add | Aligns a column of quantities to the end. Add kv-table-cell--numeric to its cells. |
scope | "col" or "colgroup" | Colgroup when colSpan is above 1. |
aria-sort | "ascending" or "descending" | On the sorted column only. |
data-sort | "ascending" or "descending" | The same, for styling. |
Table.Cell
Renders <td>, or <th scope="row"> for the row header column. It takes every attribute of a <td> and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
cell | Cell | – | The cell from row.getAllCells(). It is a <th scope="row"> for the rowHeader column and a <td> otherwise, and without children renders the column’s cell template. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-table-cell | always | The part class. |
kv-table-cell--numeric | class you add | Aligns a quantity to the end. |
kv-table-row-header | on the rowHeader column | The cell is a <th scope="row"> instead of a <td>. |
Table.SortButton
Renders <button type="button"> around the header text, with a decorative icon. It takes every attribute of a <button> except type, and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
header | Header | – | The header whose column it sorts: from table.getHeaderGroups(). |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-table-sort-button | always | The part class. |
data-sort | "ascending" or "descending" | The column is sorted. The state a screen reader reads is aria-sort on the header. |
kv-table-sort-icon | on the svg inside | The decorative icon: two chevrons while sortable, one up or down while sorted. |
Table.SelectCheckbox, Table.SelectAllCheckbox
Renders <input type="checkbox">, named by its row (or "Select all rows"). Each takes every attribute of an <input> except type, and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
row | Row | – | Table.SelectCheckbox only: the row it selects. Its name is "Select" and the row’s header cell, or "Select row 3". Table.SelectAllCheckbox takes no row. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-checkbox kv-table-select-checkbox | always | The part classes. A native checkbox. |
indeterminate | DOM property | Table.SelectAllCheckbox only: some rows are selected. |
Table.ExpandButton
Renders <button type="button"> with the text “Details” and a chevron. It takes every attribute of a <button> except type, and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
row | Row | – | The row it shows and hides the details of. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-table-expand-button | always | The part class. |
aria-expanded | "true" or "false" | The details are shown. |
aria-controls | the detail row’s id | Present while the details are shown. |
data-expanded | present or absent | The details are shown. |
kv-table-expand-icon | on the svg inside | The decorative chevron: down while hidden, up while shown. |
Table.DetailRow
Renders <tr> with one <td> that spans every column, rendered only while the row is expanded. It takes every attribute of a <tr> and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
row | Row | – | The row it belongs to. It is rendered only while the row is expanded. |
colSpan | number | – | Without a table on the Root: how many columns the detail cell spans. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-table-detail-row | always | The part class. |
data-expanded | present | The row is shown only while expanded. |
Table.Empty
Renders <tbody> with one row and one cell that spans every column, rendered only when there are no rows. It says “Loading rows.” while the table loads. It takes every attribute of a <tbody> and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | the empty message | What the cell says. Say something useful: why there are no rows and what to do next. |
colSpan | number | – | Without a table on the Root: how many columns the cell spans. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-table-empty | always | The part class. |
useTable
Takes TanStack Table’s options and the ones below. The table lists the options that most tables use. Others, such as getRowCanExpand and the on…Change handlers, work as in TanStack Table.
Options
| Prop | Type | Default | Description |
|---|---|---|---|
features | TableFeatures | Required | The TanStack Table features and row models, made with tableFeatures(). Only the features KvirnUI re-exports are supported. |
columns | ColumnDef[] | Required | The columns, made with createColumnHelper(). |
data | TData[] | Required | The rows’ data. |
getRowId | (row: TData, index: number) => string | the index | A stable id for each row. Use it, so sorting and selection follow the row. |
initialState | object | – | The state at the start: sorting, rowSelection, expanded, pagination and so on. |
state | object | – | Controlled state. Pair each slice with its on…Change option. |
region | 'overflow' | 'always' | 'overflow' | When the scroll region is a named region. Table.ScrollRegion’s own region wins. |
rowHeader | string | – | The id of the column whose cells are <th scope="row">: the one that names the row. It names the row’s checkbox and expand button too. |
virtualize | boolean | { estimateSize?: number; overscan?: number } | false | Renders only the rows near the scroll position. Estimate size defaults to 40 and overscan to 5. Ignored, with a development warning, with rowExpandingFeature. |
isLoading | boolean | false | Rows are loading: aria-busy and data-busy, and "Loading rows." is announced. |
messages | Partial<KvirnMessages["table"]> | – | Replaces strings for this table only. See Strings. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
table | TanStackTable | – | The TanStack Table instance: getHeaderGroups(), getRowModel(), setPageIndex() and so on. |
tableProps | TableRootPartProps | – | Spread on <table>. |
captionProps | TableCaptionPartProps | – | Spread on <caption>. |
scrollRegionProps | TableScrollRegionPartProps | – | Spread on the <div> around the table, for the region option. |
getScrollRegionProps | (region: TableRegion) => TableScrollRegionPartProps | – | The scroll region’s props for another region value. |
headProps | TableHeadPartProps | – | Spread on <thead>. |
bodyProps | TableBodyPartProps | – | Spread on <tbody>. |
footProps | TableFootPartProps | – | Spread on <tfoot>. |
getColumnHeaderProps | (header?: Header) => TableColumnHeaderPartProps | – | Spread on <th> in the header row. Without a header: a column you add yourself. |
getSortButtonProps | (header: Header) => TableSortButtonPartProps | – | Spread on the <button> in a sortable column header. |
getRowProps | (row: Row) => TableRowPartProps | – | Spread on <tr>. |
getCellProps | (cell: Cell) => TableCellPartProps | – | Spread on <td>, or <th scope="row"> for the rowHeader column. |
getSelectCheckboxProps | (row: Row) => TableSelectCheckboxPartProps | – | Spread on a row’s <input type="checkbox">. |
getSelectAllCheckboxProps | () => TableSelectAllCheckboxPartProps | – | Spread on the header’s <input type="checkbox">. |
getExpandButtonProps | (row: Row) => TableExpandButtonPartProps | – | Spread on a row’s expand <button>. |
getDetailRowProps | (row: Row) => TableDetailRowPartProps | – | Spread on the detail <tr>. |
emptyProps | TableEmptyPartProps | – | Spread on the empty <tbody>. |
rows | TableBodyEntry[] | – | What Table.Body renders: every row, or with virtualize the rows near the scroll position and a spacer for the rest. |
isVirtualized | boolean | – | virtualize is on, and in effect. |
isLoading | boolean | – | The table is loading rows. |
isEmpty | boolean | – | The row model has no rows. |
columnCount | number | – | How many columns are drawn, counting cells you add yourself: what a spacer, detail or empty row spans. |
footRowOffset | number | – | Virtualized: how many rows come before the footer, for a footer row’s aria-rowindex. |
emptyText | string | – | The text of the empty row. |
loadingText | string | – | The text of the empty row while the table loads and has no rows yet. |
expandButtonText | string | – | The visible text of an expand button, and the hidden text of the expand column’s header. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one Table, pass its messages prop.
table.sortedAscending
A sort button sorts a column ascending.
| Language | Default text |
|---|---|
| Svenska | Sorterad efter Name, stigande. |
| Suomi | Lajiteltu sarakkeen Name mukaan, nouseva. |
| Norsk bokmål | Sortert etter Name, stigende. |
| Norsk nynorsk | Sortert etter Name, stigande. |
| English | Sorted by Name, ascending. |
table.sortedDescending
A sort button sorts a column descending.
| Language | Default text |
|---|---|
| Svenska | Sorterad efter Name, fallande. |
| Suomi | Lajiteltu sarakkeen Name mukaan, laskeva. |
| Norsk bokmål | Sortert etter Name, synkende. |
| Norsk nynorsk | Sortert etter Name, synkande. |
| English | Sorted by Name, descending. |
table.sortCleared
A sort button removes the sort.
| Language | Default text |
|---|---|
| Svenska | Inte längre sorterad efter Name. |
| Suomi | Lajittelu sarakkeen Name mukaan on poistettu. |
| Norsk bokmål | Ikke lenger sortert etter Name. |
| Norsk nynorsk | Ikkje lenger sortert etter Name. |
| English | No longer sorted by Name. |
table.selectRow
The name of a row’s select checkbox.
| Language | Default text |
|---|---|
| Svenska | Välj |
| Suomi | Valitse |
| Norsk bokmål | Velg |
| Norsk nynorsk | Vel |
| English | Select |
table.selectRowNumber
The name of a row’s select checkbox when there is no row header, numbered.
| Language | Default text |
|---|---|
| Svenska | Välj rad 3 |
| Suomi | Valitse rivi 3 |
| Norsk bokmål | Velg rad 3 |
| Norsk nynorsk | Vel rad 3 |
| English | Select row 3 |
table.selectAllRows
The name of the select-all checkbox.
| Language | Default text |
|---|---|
| Svenska | Välj alla rader |
| Suomi | Valitse kaikki rivit |
| Norsk bokmål | Velg alle rader |
| Norsk nynorsk | Vel alle rader |
| English | Select all rows |
table.selectedCount
Announced when the select-all checkbox changes the selection.
| Language | Default text |
|---|---|
| Svenska | 12 rader markerade. |
| Suomi | 12 riviä valittu. |
| Norsk bokmål | 12 rader valgt. |
| Norsk nynorsk | 12 rader valde. |
| English | 12 rows selected. |
table.rowCount
Announced when a filter changed the rows.
| Language | Default text |
|---|---|
| Svenska | 3 rader. |
| Suomi | 3 riviä. |
| Norsk bokmål | 3 rader. |
| Norsk nynorsk | 3 rader. |
| English | 3 rows. |
table.loading
Announced when isLoading becomes true.
| Language | Default text |
|---|---|
| Svenska | Laddar rader. |
| Suomi | Ladataan rivejä. |
| Norsk bokmål | Laster rader. |
| Norsk nynorsk | Lastar rader. |
| English | Loading rows. |
table.empty
The text of Table.Empty when there are no rows.
| Language | Default text |
|---|---|
| Svenska | Det finns inga rader att visa. |
| Suomi | Ei näytettäviä rivejä. |
| Norsk bokmål | Det er ingen rader å vise. |
| Norsk nynorsk | Det er ingen rader å vise. |
| English | No rows to show. |
table.rowDetails
The name of a row’s expand button.
| Language | Default text |
|---|---|
| Svenska | Detaljer |
| Suomi | Lisätiedot |
| Norsk bokmål | Detaljer |
| Norsk nynorsk | Detaljar |
| English | Details |
table.rowDetailsNumber
The name of a row’s expand button when there is no row header, numbered.
| Language | Default text |
|---|---|
| Svenska | Detaljer rad 3 |
| Suomi | Lisätiedot rivi 3 |
| Norsk bokmål | Detaljer rad 3 |
| Norsk nynorsk | Detaljar rad 3 |
| English | Details row 3 |
Known issues#
- Screen readers may differ in how they report
aria-rowcountandaria-rowindex. Test it with the screen readers your users have. - A virtualized table can't be searched with find-in-page, isn't printed in full, and Tab can't reach a control in a row that isn't rendered. Pagination or a filter is the recommended default.
- Shift+click range selection and multi-sort are not offered: each needs a key the pattern doesn't document.
- The select-all checkbox always means every row of the table. A "this page only" variant is not offered.
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 | table.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | table.test.tsx › a native table named by its caption, with column headers and row headers; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 14 rows, each names a test (table.test.tsx › Tab focuses the scroll region when the table overflows) |
| Focus order and management | pass | n/a | pass | table.test.tsx asserts focus (toHaveFocus); first rule: Tab focuses the scroll region when the table overflows |
| 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:
- With table commands, each cell is read with its column and row header.
- Press a sort button three times: "Sorted by Name, ascending.", then descending, then "No longer sorted by Name."
- A row checkbox is named "Select" plus the row name. Select-all reads the count after Space.
- An expand button reads "Details" plus the row name, with expanded or collapsed, and then the detail row.
- In a virtualized table the row count and each row's place are read.
- A checkbox named by its own label and the row header is read the same in every combination.
- At 320px, Tab reaches the named scroll region and the arrow keys scroll it.