Data display
Table
Free15.8 KB gzippedSemantic data table. See TableRoot docs above; parts are attached as Table.*.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Enter, Space · Full report
Import
import { Table } from "@vjdesigns/vjdesigns-ui";
Importing only Table adds about 15.8 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Sortable
useTableSort sorts a copy of your rows and hands each header cell its sort props.
| Marcus Hill | SF | 22.9 | 3.2 |
|---|---|---|---|
| Avery Johnson | PG | 18.4 | 7.1 |
| Chris Wong | SG | 16.7 | 4.4 |
| Dana Ortiz | C | 14.1 | 1.8 |
import { Table, useTableSort } from "@vjdesigns/vjdesigns-ui";
export function Sortable() {
const players = [
{ name: "Avery Johnson", position: "PG", ppg: 18.4, apg: 7.1 },
{ name: "Marcus Hill", position: "SF", ppg: 22.9, apg: 3.2 },
{ name: "Dana Ortiz", position: "C", ppg: 14.1, apg: 1.8 },
{ name: "Chris Wong", position: "SG", ppg: 16.7, apg: 4.4 },
];
const { sortedRows, getSortProps } = useTableSort(players, {
initial: { key: "ppg", direction: "descending" },
});
return (
<div style={{ width: "100%" }}>
<Table variant="outline" hoverable>
<Table.Caption>Season averages</Table.Caption>
<Table.Head>
<Table.Row>
<Table.HeaderCell {...getSortProps("name")}>Player</Table.HeaderCell>
<Table.HeaderCell {...getSortProps("position")}>Pos</Table.HeaderCell>
<Table.HeaderCell numeric {...getSortProps("ppg")}>
PPG
</Table.HeaderCell>
<Table.HeaderCell numeric {...getSortProps("apg")}>
APG
</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
{sortedRows.map((player) => (
<Table.Row key={player.name}>
<Table.HeaderCell>{player.name}</Table.HeaderCell>
<Table.Cell>{player.position}</Table.Cell>
<Table.Cell numeric>{player.ppg.toFixed(1)}</Table.Cell>
<Table.Cell numeric>{player.apg.toFixed(1)}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table>
</div>
);
}
Selectable
useTableSelection drives row checkboxes and the indeterminate "select all" box.
| Invoice | Customer | Amount | Status | |
|---|---|---|---|---|
| INV-1042 | Northwind | $1,280.00 | Paid | |
| INV-1043 | Acme Co. | $640.00 | Due | |
| INV-1044 | Globex | $3,150.00 | Overdue |
0 selected
import {
Badge,
Button,
Stack,
Table,
Text,
useTableSelection,
} from "@vjdesigns/vjdesigns-ui";
export function Selectable() {
const invoices = [
{ id: "INV-1042", customer: "Northwind", amount: "$1,280.00", status: "Paid" },
{ id: "INV-1043", customer: "Acme Co.", amount: "$640.00", status: "Due" },
{ id: "INV-1044", customer: "Globex", amount: "$3,150.00", status: "Overdue" },
];
const selection = useTableSelection(
invoices.map((invoice) => invoice.id),
{ getRowLabel: (id) => `Select invoice ${id}` },
);
const tone = { Paid: "success", Due: "info", Overdue: "danger" } as const;
return (
<Stack gap={3} style={{ width: "100%" }}>
<Table variant="striped" stackBelow="sm">
<Table.Caption>Invoices</Table.Caption>
<Table.Head>
<Table.Row>
<Table.SelectAllCell {...selection.getSelectAllProps()} />
<Table.HeaderCell>Invoice</Table.HeaderCell>
<Table.HeaderCell>Customer</Table.HeaderCell>
<Table.HeaderCell numeric>Amount</Table.HeaderCell>
<Table.HeaderCell>Status</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
{invoices.map((invoice) => (
<Table.Row key={invoice.id} selected={selection.isSelected(invoice.id)}>
<Table.SelectCell {...selection.getSelectProps(invoice.id)} />
<Table.HeaderCell>{invoice.id}</Table.HeaderCell>
<Table.Cell label="Customer">{invoice.customer}</Table.Cell>
<Table.Cell label="Amount" numeric>
{invoice.amount}
</Table.Cell>
<Table.Cell label="Status">
<Badge tone={tone[invoice.status as keyof typeof tone]}>{invoice.status}</Badge>
</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table>
<Stack direction="row" align="center" gap={3}>
<Text size="sm" tone="muted">
{selection.count} selected
</Text>
<Button size="sm" variant="outline" tone="neutral" disabled={!selection.count} onClick={selection.clear}>
Clear selection
</Button>
</Stack>
</Stack>
);
}
Accessibility
Table.Caption names the table, and scope="row" makes each region a row header, so screen readers announce "Europe, Q3 revenue, $1.2M". Below stackBelow, rows become cards with each value labeled by its column header, and the parts keep explicit table roles.
| Region | Q3 revenue | Change |
|---|---|---|
| Americas | $2.4M | +8% |
| Europe | $1.2M | +3% |
| Asia Pacific | $0.9M | −2% |
import { Table } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
const rows = [
{ region: "Americas", revenue: "$2.4M", change: "+8%" },
{ region: "Europe", revenue: "$1.2M", change: "+3%" },
{ region: "Asia Pacific", revenue: "$0.9M", change: "−2%" },
];
return (
<Table variant="outline" stackBelow="sm">
<Table.Caption>Revenue by region, Q3</Table.Caption>
<Table.Head>
<Table.Row>
<Table.HeaderCell>Region</Table.HeaderCell>
<Table.HeaderCell numeric>Q3 revenue</Table.HeaderCell>
<Table.HeaderCell numeric>Change</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
{rows.map((row) => (
<Table.Row key={row.region}>
<Table.HeaderCell scope="row">{row.region}</Table.HeaderCell>
<Table.Cell numeric>{row.revenue}</Table.Cell>
<Table.Cell numeric>{row.change}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table>
);
}
Translated
The select-all and row checkboxes get their names from the locale and each row's rowLabel (Brazilian Portuguese here), as do the loading text and the scroll region's name.
| Nome | Área | |
|---|---|---|
| Ana Souza | Design | |
| Bruno Lima | Engenharia | |
| Carla Dias | Marketing |
import { useState } from "react";
import { Table, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ptBR from "@vjdesigns/vjdesigns-ui/locales/pt-BR";
export function Translated() {
const people = [
{ id: "1", name: "Ana Souza", role: "Design" },
{ id: "2", name: "Bruno Lima", role: "Engenharia" },
{ id: "3", name: "Carla Dias", role: "Marketing" },
];
const [selected, setSelected] = useState<string[]>(["1"]);
const all = selected.length === people.length;
return (
<LocaleProvider locale="pt-BR" messages={ptBR}>
<Table variant="outline">
<Table.Caption>Equipe</Table.Caption>
<Table.Head>
<Table.Row>
<Table.SelectAllCell
checked={all}
indeterminate={selected.length > 0 && !all}
onCheckedChange={(checked) => setSelected(checked ? people.map((p) => p.id) : [])}
/>
<Table.HeaderCell>Nome</Table.HeaderCell>
<Table.HeaderCell>Área</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
{people.map((person) => (
<Table.Row key={person.id} selected={selected.includes(person.id)}>
<Table.SelectCell
rowLabel={person.name}
checked={selected.includes(person.id)}
onCheckedChange={(checked) =>
setSelected((ids) => (checked ? [...ids, person.id] : ids.filter((id) => id !== person.id)))
}
/>
<Table.Cell>{person.name}</Table.Cell>
<Table.Cell>{person.role}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Sortable
| Marcus Hill | SF | 22.9 | 3.2 |
|---|---|---|---|
| Avery Johnson | PG | 18.4 | 7.1 |
| Chris Wong | SG | 16.7 | 4.4 |
| Dana Ortiz | C | 14.1 | 1.8 |
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Sortable is the "Sortable" example above.
<LocaleProvider locale="ar" messages={ar}>
<Sortable />
</LocaleProvider>
API reference
Table
| Prop | Type | Default |
|---|---|---|
variantVisual style. | "plain""striped""outline" | "plain" |
densityCell padding and row height. | "compact""comfortable""spacious" | "comfortable" |
stickyHeaderKeeps the header row visible while the body scrolls. Combine with | boolean | false |
maxHeightMaximum height of the scroll container (any CSS length). Rows past it scroll vertically. | string | number | "var(--container-xs)" when `stickyHeader`, otherwise none |
stickyFirstColumnPins the first column while the table scrolls horizontally. | boolean | false |
hoverableHighlights body rows under the pointer. | boolean | false |
layoutCSS | "auto""fixed" | "auto" |
fullWidthStretches the table to the container's width. | boolean | true |
captionSideCaption placement. | "top""bottom" | "top" |
loadingShows a spinner over the table, dims the body, and sets | boolean | false |
loadingLabelText announced by the loading spinner. | string | "Loading" |
stackBelowTurns rows into stacked cards below this viewport width, labelling each value with its column header ( | "sm""md" | — |
scrollLabelAccessible name for the scroll region, used when the table overflows and has no | string | "Scrollable table" |
classNameClass name for the outer frame. Every other prop goes on the | string | — |
styleInline style for the outer frame. | CSSProperties | — |
childrenTable sections and caption. | ReactNode | — |
Also accepts native <table> attributes, plus className, style and ref.
Table.Caption
The table's title (<caption>). It names the table and, when the table scrolls, its scroll region. Strongly recommended on every table.
Also accepts standard HTML attributes, plus className, style and ref.
Table.Head
The header section (<thead>). Its last row supplies column labels for stackBelow.
Also accepts standard HTML attributes, plus className, style and ref.
Table.Body
The body section (<tbody>).
Also accepts standard HTML attributes, plus className, style and ref.
Table.Foot
The footer section (<tfoot>), for totals and summaries.
Also accepts standard HTML attributes, plus className, style and ref.
Table.Row
A table row (<tr>).
| Prop | Type | Default |
|---|---|---|
selectedShows the row as selected. Visual only: | boolean | false |
Also accepts native <tr> attributes, plus className, style and ref.
Table.HeaderCell
A header cell (<th>). With sortable, the whole cell is a real <button> and the header carries aria-sort while it is the sorted column. The sort icon shows the direction by shape (up arrow, down arrow, or a neutral double arrow), not by color alone.
| Prop | Type | Default |
|---|---|---|
scopeWhich cells this header labels. | "col""row""colgroup""rowgroup" | "col" in `Table.Head` and
`Table.Foot`, "row" in `Table.Body` (use a header cell for each row's
key column, such as a player's name) |
sortableRenders the header as a sort button. | boolean | false |
sortDirectionCurrent sort of this column. Sets | "ascending""descending""none" | "none" |
onSortCalled when the sort button is pressed, with the suggested next direction ( | (nextDirection: TableSortDirection) => void | — |
alignHorizontal alignment. | "start""center""end" | "start" ("end" when `numeric`) |
numericTabular, end-aligned numbers in the display font. | boolean | false |
truncateKeeps content on one line and cuts it off with an ellipsis. Works best with | boolean | false |
widthColumn width (a number of pixels or any CSS length). | number | string | — |
Also accepts native <th> attributes, plus className, style and ref.
Table.Cell
A data cell (<td>).
| Prop | Type | Default |
|---|---|---|
labelColumn label shown beside the value when rows are stacked ( | string | — |
alignHorizontal alignment. | "start""center""end" | "start" ("end" when `numeric`) |
numericTabular, end-aligned numbers in the display font. | boolean | false |
truncateKeeps content on one line and cuts it off with an ellipsis. Works best with | boolean | false |
widthColumn width (a number of pixels or any CSS length). | number | string | — |
Also accepts native <td> attributes, plus className, style and ref.
Table.SelectCell
A data cell holding the row's selection checkbox. Pair with selected on the Table.Row. Give it a rowLabel (or checkboxLabel) so each checkbox has a unique accessible name.
| Prop | Type | Default |
|---|---|---|
checkedRequiredWhether the row is selected. | boolean | — |
onCheckedChangeRequiredCalled with the next checked state. | (checked: boolean) => void | — |
rowLabelReadable name of the row, used for the checkbox's accessible name: "Select row {rowLabel}". Ignored when | string | — |
checkboxLabelFull accessible name for the checkbox, overriding the "Select row" pattern. | string | — |
disabledPrevents changing this row's selection. | boolean | false |
Also accepts native <td> attributes, plus className, style and ref.
Table.SelectAllCell
A header cell (<th scope="col">) with a "select all" checkbox. Shows the mixed state (aria-checked="mixed") when some rows are selected.
| Prop | Type | Default |
|---|---|---|
checkedRequiredWhether every row is selected. | boolean | — |
indeterminateWhether some, but not all, rows are selected (mixed state). | boolean | false |
onCheckedChangeRequiredCalled with the next checked state. | (checked: boolean) => void | — |
checkboxLabelAccessible name for the checkbox. | string | "Select all rows" |
disabledPrevents changing the selection. | boolean | false |
Also accepts native <th> attributes, plus className, style and ref.
Table.Empty
A full-width row for an empty result. Place it inside Table.Body.
| Prop | Type | Default |
|---|---|---|
colSpanNumber of columns to span. | number | the measured header column count |
iconDecorative icon above the message. | ReactNode | — |
headingBold heading, such as "No players yet". | ReactNode | — |
childrenSupporting message. | ReactNode | — |
actionAn action, such as a "Clear filters" button. | ReactNode | — |
Also accepts native <tr> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Table targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Dark mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves through sort buttons, selection checkboxes and controls in cells. |
| EnterSpace | Sorts by the focused column. |
| Space | Selects or clears the focused row's checkbox. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
<table> | table | <caption> names it |
| Header cell | columnheader / rowheader | aria-sort on the sorted column |
| Selection checkbox | checkbox | aria-label ("Select row …", "Select all") |
| Scrolling wrapper | region | aria-label |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |