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.

Table

A data table built on the native table elements. A screen reader (software that reads the screen aloud) reads each cell together with its row and column headers. A table can also sort, select and expand rows and show long lists, and it stays a real table.

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

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#

Housing allowance paid in 2026
MonthPayout dateAmount (SEK)
January1/23/261,050
February2/25/261,050
March3/25/261,050
Total3,150

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.

Open cases
Handler
Anna SvenssonBN 2026-01424,200Karin Lund
Erik LindqvistBN 2026-016312,500Karin Lund
Zacharias NilssonBN 2026-0171960Maria Berg
Åsa ÖbergBN 2026-01571,850Johan Ek
Ärlig HolmBN 2026-01887,300Johan Ek

Props in this example:

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.

Open cases
NameCase numberHandler
Anna SvenssonBN 2026-0142Karin Lund
Åsa ÖbergBN 2026-0157Johan Ek
Erik LindqvistBN 2026-0163Karin Lund
Zacharias NilssonBN 2026-0171Maria Berg
Ärlig HolmBN 2026-0188Johan Ek

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.

Open cases
Anna SvenssonBN 2026-01424,200
Åsa ÖbergBN 2026-01571,850
Erik LindqvistBN 2026-016312,500
Zacharias NilssonBN 2026-0171960
Ärlig HolmBN 2026-01887,300

Props in this example:

  • row on Table.SelectCheckbox, Table.SelectAllCheckbox
  • rowHeader on useTable (options)

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.

Open cases
DetailsNameCase numberAmount (SEK)
Anna SvenssonBN 2026-01424,200
Åsa ÖbergBN 2026-01571,850
Handler
Johan Ek
Decision
More information needed
Erik LindqvistBN 2026-016312,500
Zacharias NilssonBN 2026-0171960
Ärlig HolmBN 2026-01887,300

Props in this example:

  • row on Table.ExpandButton
  • row on Table.DetailRow

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.

Open cases
NameCase number
You have no open cases. New applications show up here when you send them.

Props in this example:

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.

All cases
Anna Svensson 1BN 2026-1000500
Åsa Öberg 2BN 2026-10011,437
Erik Lindqvist 3BN 2026-10022,374
Zacharias Nilsson 4BN 2026-10033,311
Ärlig Holm 5BN 2026-10044,248
Anna Svensson 6BN 2026-10055,185
Åsa Öberg 7BN 2026-10066,122
Erik Lindqvist 8BN 2026-10077,059
Zacharias Nilsson 9BN 2026-10087,996
Ärlig Holm 10BN 2026-10098,933
Anna Svensson 11BN 2026-10109,870
Åsa Öberg 12BN 2026-101110,807
Erik Lindqvist 13BN 2026-101211,744
Zacharias Nilsson 14BN 2026-101312,681
Ärlig Holm 15BN 2026-101413,618
Anna Svensson 16BN 2026-101514,555
Åsa Öberg 17BN 2026-101615,492
Erik Lindqvist 18BN 2026-101716,429

Props in this example:

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 no role="grid".
  • Native elements used: <table>, <caption>, <thead>, <tbody>, <tfoot>, <tr>, <th scope>, <td>, <button> (sort and expand), <input type="checkbox"> (selection), <div> that is a role="region" while it scrolls, or always with region="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.

PartElement / roleARIA / stateNotes
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-virtualizedClass 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 tabindexClasses 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>noneClass kv-table-caption. The table's name, and the region's
Table.Head, Body, Foot<thead>, <tbody>, <tfoot>noneClasses 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>noneClasses 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 headerdata-sort. The state is aria-sort on the header, never the iconClass 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 selectedClasses 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 itClass 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 columndata-expandedClass 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 columnnoneClass 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-hiddenClass 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
useTablethe same attributes, for your own elementstableProps, captionProps, scrollRegionProps, headProps, bodyProps, getColumnHeaderProps, getSortButtonProps, getRowProps, getCellProps, getSelectCheckboxProps, getSelectAllCheckboxProps, getExpandButtonProps, getDetailRowProps, emptyProps, rowsOptions: 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 the display of a table element, because some browsers then drop the table semantics. There is no role="table", row or cell anywhere.
  • A name is required. Table.Caption, or aria-labelledby on the Root pointing at a visible heading. A table with neither warns once in development. While the scroll region is a region (it scrolls, or region="always") it is named by the caption through aria-labelledby, so the table and its region are one thing to a user. A table with no caption names the region with aria-labelledby or aria-label on Table.ScrollRegion: a region with no name is an unlabelled landmark (4.1.2 Name, Role, Value, A).
  • aria-sort is on the sorted column only. Not on the other sortable columns (none is 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. enableMultiSort is always false: 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-sort changes 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 with Intl.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, through aria-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 a rowHeader the name is "Select row 3", from the row's place in the row model.
  • Selected rows have data-selected, never aria-selected. ARIA 1.2 allows aria-selected on 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-expanded and aria-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 no rowHeader the name is table.rowDetailsNumber ("Details row 3"), which also starts with the visible text. The name doesn't change: only aria-expanded does. 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. isLoading sets aria-busy="true" and data-busy and announces "Loading rows." An empty row model shows Table.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 by aria-hidden spacer rows. The table has aria-rowcount (the header rows, every row of the data and the rows of Table.Foot) and each rendered row has aria-rowindex, so a screen reader knows how big the table is and where a row is. A header row without a headerGroup, 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 (focusin on 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 without table measures 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: fixed comes 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 useTable prop objects on your own.
  • Dev warnings: no name, a function as the Body's children with no table on the Root, a select checkbox with no rowSelectionFeature, virtualize with rowExpandingFeature, 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.Caption or aria-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 a Table.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--numeric on the header and kv-table-cell--numeric on 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, focusable region, and when it fits, a plain <div>. Add region="always" to make it a named region either way. Name it: a Table.Caption with table, or aria-labelledby or aria-label on 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 with display: 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-motion alone 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-sort and 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 under prefers-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 focusin and focusout, 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 to body because a row was unmounted.
  • Never obscured by: the sticky header. Table.ScrollRegion measures the header's height, with or without useTable, 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 its tabindex, 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 no tabindex, 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" (on Table.ScrollRegion or useTable) 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#

SCNameHow
1.3.1Info and Relationships (A)A native table, caption, <th scope>, aria-sort, and names for every checkbox and button
1.3.2Meaningful Sequence (A)The DOM order is the reading order. Spacer rows are hidden
1.4.1Use of Color (A)Sort state, selection and expansion are in attributes, text and shape, never colour alone
1.4.10Reflow (AA)A data table is exempt, and it scrolls inside a focusable region, named while it scrolls
1.4.11Non-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.12Text Spacing (AA)Cells have no fixed height, so spacing doesn't clip text (the text-spacing sweep checks it)
2.1.1Keyboard (A)Every control is a native button or checkbox. The scroll region is focusable while it scrolls
2.4.3Focus Order (A)Tab follows the reading order. A focused row stays rendered
2.4.7Focus Visible (AA)Every control and the scroll region show focus
2.4.11Focus Not Obscured (Minimum) (AA)The scroll padding is the sticky header's height (no automated test measures it)
2.5.3Label in Name (A)Visible text names its button: the header text, and the visible text of an expand button
2.5.8Target Size (Minimum) (AA)Checkboxes are 24 by 24 CSS pixels, sort and expand buttons larger
3.2.2On Input (A)Sorting, selecting or expanding never changes context: focus stays on the control and nothing navigates or opens
4.1.2Name, Role, Value (A)Native roles. Checkboxes, sort buttons and expand buttons have names and states
4.1.3Status 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
KeyWhereWhat happens
Tabbefore the tableMoves 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
Tabin the tableMoves 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+Tabin the tableMoves 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
Enteron a sort buttonSorts 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
Spaceon a sort buttonSame as Enter
Test: table.test.tsx › Space on a sort button sorts the column
Spaceon a row checkboxSelects or deselects the row
Test: table.test.tsx › Space on a row checkbox selects the row
Spaceon the select-all checkboxSelects or deselects every row, and announces the count
Test: table.test.tsx › Space on select-all selects every row and announces the count
Enteron an expand buttonShows the row's details
Test: table.test.tsx › Enter on an expand button shows the details
Spaceon an expand buttonHides the row's details again
Test: table.test.tsx › Space on an expand button hides the details
Tabon a control in a row of a virtualized tableMoves 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 rendered
Test: table.test.tsx › A focused row stays rendered while the virtualized table scrolls
ArrowDownon the focused scroll regionScrolls the table down (native)
Test: table.test.tsx › ArrowDown scrolls the focused scroll region
ArrowRighton the focused scroll regionScrolls 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
PageDownon the focused scroll regionScrolls the table a page (native)
Test: table.test.tsx › PageDown scrolls the focused scroll region a page
Escape / any characteranywhere in the tableNothing. 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).

WhenWhat it saysMessage keyPoliteness
A sort button sorts a column ascendingSorted by Name, ascending.table.sortedAscendingPolite
A sort button sorts a column descendingSorted by Name, descending.table.sortedDescendingPolite
A sort button removes the sortNo longer sorted by Name.table.sortClearedPolite
The select-all checkbox changes the selection12 rows selected.table.selectedCountPolite
A filter changed the rows (after 500 ms)3 rows.table.rowCountPolite
isLoading became trueLoading rows.table.loadingPolite

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.

PropTypeDefaultDescription
tableUseTableResult–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 attributeValuesMeaning
kv-tablealwaysThe part class.
aria-busy"true" or absentRows are loading (isLoading).
data-busypresent or absentRows are loading (isLoading).
data-virtualizedpresent or absentvirtualize is on.
aria-rowcounta numberVirtualized 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.

PropTypeDefaultDescription
tableUseTableResult–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 attributeValuesMeaning
kv-scroll-region kv-table-scroll-regionalwaysThe part classes.
role"region" or absentA named region while the table scrolls, or always with region="always".
aria-labelledbythe caption’s idNames the region, while it is one and the table has a caption. Yours replaces it.
tabindex"0" or absentA Tab stop only while the table scrolls, so a keyboard user can scroll it.
data-overflowingpresent or absentThe table scrolls.
--kv-table-head-block-sizea length in pxSet 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 attributeValuesMeaning
kv-table-captionalwaysTable.Caption: the table’s name.
kv-table-headalwaysTable.Head.
kv-table-footalwaysTable.Foot.
kv-table-row-headeralwaysTable.RowHeader: renders <th scope="row">.

Table.Body

Renders <tbody>. It takes every attribute of a <tbody> and passes ref to it.

PropTypeDefaultDescription
childrenReactNode | ((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 attributeValuesMeaning
kv-table-bodyalwaysThe part class.
kv-table-spaceron a row you do not renderVirtualized 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.

PropTypeDefaultDescription
rowRow–The row of the row model: sets data-selected, data-expanded and, virtualized, aria-rowindex.
headerGroupHeaderGroup–In the head: the header group the row shows, for aria-rowindex when virtualized.
Class or attributeValuesMeaning
kv-table-rowalwaysThe part class.
data-selectedpresent or absentThe row is selected.
data-expandedpresent or absentThe row’s details are shown.
data-indexa numberVirtualized only: the row’s place in the data.
aria-rowindexa numberVirtualized 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.

PropTypeDefaultDescription
headerHeader–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 attributeValuesMeaning
kv-table-column-headeralwaysThe part class.
kv-table-column-header--numericclass you addAligns 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.

PropTypeDefaultDescription
cellCell–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 attributeValuesMeaning
kv-table-cellalwaysThe part class.
kv-table-cell--numericclass you addAligns a quantity to the end.
kv-table-row-headeron the rowHeader columnThe 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.

PropTypeDefaultDescription
headerHeader–The header whose column it sorts: from table.getHeaderGroups().
Class or attributeValuesMeaning
kv-table-sort-buttonalwaysThe 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-iconon the svg insideThe 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.

PropTypeDefaultDescription
rowRow–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 attributeValuesMeaning
kv-checkbox kv-table-select-checkboxalwaysThe part classes. A native checkbox.
indeterminateDOM propertyTable.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.

PropTypeDefaultDescription
rowRow–The row it shows and hides the details of.
Class or attributeValuesMeaning
kv-table-expand-buttonalwaysThe part class.
aria-expanded"true" or "false"The details are shown.
aria-controlsthe detail row’s idPresent while the details are shown.
data-expandedpresent or absentThe details are shown.
kv-table-expand-iconon the svg insideThe 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.

PropTypeDefaultDescription
rowRow–The row it belongs to. It is rendered only while the row is expanded.
colSpannumber–Without a table on the Root: how many columns the detail cell spans.
Class or attributeValuesMeaning
kv-table-detail-rowalwaysThe part class.
data-expandedpresentThe 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.

PropTypeDefaultDescription
childrenReactNodethe empty messageWhat the cell says. Say something useful: why there are no rows and what to do next.
colSpannumber–Without a table on the Root: how many columns the cell spans.
Class or attributeValuesMeaning
kv-table-emptyalwaysThe 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

PropTypeDefaultDescription
featuresTableFeaturesRequiredThe TanStack Table features and row models, made with tableFeatures(). Only the features KvirnUI re-exports are supported.
columnsColumnDef[]RequiredThe columns, made with createColumnHelper().
dataTData[]RequiredThe rows’ data.
getRowId(row: TData, index: number) => stringthe indexA stable id for each row. Use it, so sorting and selection follow the row.
initialStateobject–The state at the start: sorting, rowSelection, expanded, pagination and so on.
stateobject–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.
rowHeaderstring–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.
virtualizeboolean | { estimateSize?: number; overscan?: number }falseRenders only the rows near the scroll position. Estimate size defaults to 40 and overscan to 5. Ignored, with a development warning, with rowExpandingFeature.
isLoadingbooleanfalseRows are loading: aria-busy and data-busy, and "Loading rows." is announced.
messagesPartial<KvirnMessages["table"]>–Replaces strings for this table only. See Strings.

Result

PropTypeDefaultDescription
tableTanStackTable–The TanStack Table instance: getHeaderGroups(), getRowModel(), setPageIndex() and so on.
tablePropsTableRootPartProps–Spread on <table>.
captionPropsTableCaptionPartProps–Spread on <caption>.
scrollRegionPropsTableScrollRegionPartProps–Spread on the <div> around the table, for the region option.
getScrollRegionProps(region: TableRegion) => TableScrollRegionPartProps–The scroll region’s props for another region value.
headPropsTableHeadPartProps–Spread on <thead>.
bodyPropsTableBodyPartProps–Spread on <tbody>.
footPropsTableFootPartProps–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>.
emptyPropsTableEmptyPartProps–Spread on the empty <tbody>.
rowsTableBodyEntry[]–What Table.Body renders: every row, or with virtualize the rows near the scroll position and a spacer for the rest.
isVirtualizedboolean–virtualize is on, and in effect.
isLoadingboolean–The table is loading rows.
isEmptyboolean–The row model has no rows.
columnCountnumber–How many columns are drawn, counting cells you add yourself: what a spacer, detail or empty row spans.
footRowOffsetnumber–Virtualized: how many rows come before the footer, for a footer row’s aria-rowindex.
emptyTextstring–The text of the empty row.
loadingTextstring–The text of the empty row while the table loads and has no rows yet.
expandButtonTextstring–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.

LanguageDefault text
SvenskaSorterad efter Name, stigande.
SuomiLajiteltu sarakkeen Name mukaan, nouseva.
Norsk bokmålSortert etter Name, stigende.
Norsk nynorskSortert etter Name, stigande.
EnglishSorted by Name, ascending.

table.sortedDescending

A sort button sorts a column descending.

LanguageDefault text
SvenskaSorterad efter Name, fallande.
SuomiLajiteltu sarakkeen Name mukaan, laskeva.
Norsk bokmålSortert etter Name, synkende.
Norsk nynorskSortert etter Name, synkande.
EnglishSorted by Name, descending.

table.sortCleared

A sort button removes the sort.

LanguageDefault text
SvenskaInte längre sorterad efter Name.
SuomiLajittelu sarakkeen Name mukaan on poistettu.
Norsk bokmålIkke lenger sortert etter Name.
Norsk nynorskIkkje lenger sortert etter Name.
EnglishNo longer sorted by Name.

table.selectRow

The name of a row’s select checkbox.

LanguageDefault text
SvenskaVälj
SuomiValitse
Norsk bokmålVelg
Norsk nynorskVel
EnglishSelect

table.selectRowNumber

The name of a row’s select checkbox when there is no row header, numbered.

LanguageDefault text
SvenskaVälj rad 3
SuomiValitse rivi 3
Norsk bokmålVelg rad 3
Norsk nynorskVel rad 3
EnglishSelect row 3

table.selectAllRows

The name of the select-all checkbox.

LanguageDefault text
SvenskaVälj alla rader
SuomiValitse kaikki rivit
Norsk bokmålVelg alle rader
Norsk nynorskVel alle rader
EnglishSelect all rows

table.selectedCount

Announced when the select-all checkbox changes the selection.

LanguageDefault text
Svenska12 rader markerade.
Suomi12 riviä valittu.
Norsk bokmål12 rader valgt.
Norsk nynorsk12 rader valde.
English12 rows selected.

table.rowCount

Announced when a filter changed the rows.

LanguageDefault text
Svenska3 rader.
Suomi3 riviä.
Norsk bokmål3 rader.
Norsk nynorsk3 rader.
English3 rows.

table.loading

Announced when isLoading becomes true.

LanguageDefault text
SvenskaLaddar rader.
SuomiLadataan rivejä.
Norsk bokmålLaster rader.
Norsk nynorskLastar rader.
EnglishLoading rows.

table.empty

The text of Table.Empty when there are no rows.

LanguageDefault text
SvenskaDet finns inga rader att visa.
SuomiEi näytettäviä rivejä.
Norsk bokmålDet er ingen rader å vise.
Norsk nynorskDet er ingen rader å vise.
EnglishNo rows to show.

table.rowDetails

The name of a row’s expand button.

LanguageDefault text
SvenskaDetaljer
SuomiLisätiedot
Norsk bokmålDetaljer
Norsk nynorskDetaljar
EnglishDetails

table.rowDetailsNumber

The name of a row’s expand button when there is no row header, numbered.

LanguageDefault text
SvenskaDetaljer rad 3
SuomiLisätiedot rivi 3
Norsk bokmålDetaljer rad 3
Norsk nynorskDetaljar rad 3
EnglishDetails row 3

Known issues#

  • Screen readers may differ in how they report aria-rowcount and aria-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 + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespassn/apasstable.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apasstable.test.tsx › a native table named by its caption, with column headers and row headers; expectNoA11yViolations
Keyboard contract rows (Vitest browser)passn/apass14 rows, each names a test (table.test.tsx › Tab focuses the scroll region when the table overflows)
Focus order and managementpassn/apasstable.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)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#

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.