Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Data display

Table

Free15.8 KB gzipped

Semantic 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

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

Season averages
Marcus HillSF22.93.2
Avery JohnsonPG18.47.1
Chris WongSG16.74.4
Dana OrtizC14.11.8
tsx
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.

Invoices
InvoiceCustomerAmountStatus
INV-1042Northwind$1,280.00Paid
INV-1043Acme Co.$640.00Due
INV-1044Globex$3,150.00Overdue

0 selected

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

Revenue by region, Q3
RegionQ3 revenueChange
Americas$2.4M+8%
Europe$1.2M+3%
Asia Pacific$0.9M−2%
tsx
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.

Equipe
NomeÁrea
Ana SouzaDesign
Bruno LimaEngenharia
Carla DiasMarketing
tsx
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

Season averages
Marcus HillSF22.93.2
Avery JohnsonPG18.47.1
Chris WongSG16.74.4
Dana OrtizC14.11.8
tsx
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

Table props
PropTypeDefault
variant

Visual style.

"plain""striped""outline""plain"
density

Cell padding and row height.

"compact""comfortable""spacious""comfortable"
stickyHeader

Keeps the header row visible while the body scrolls. Combine with maxHeight.

booleanfalse
maxHeight

Maximum height of the scroll container (any CSS length). Rows past it scroll vertically.

string | number"var(--container-xs)" when `stickyHeader`, otherwise none
stickyFirstColumn

Pins the first column while the table scrolls horizontally.

booleanfalse
hoverable

Highlights body rows under the pointer.

booleanfalse
layout

CSS table-layout.

"auto""fixed""auto"
fullWidth

Stretches the table to the container's width.

booleantrue
captionSide

Caption placement.

"top""bottom""top"
loading

Shows a spinner over the table, dims the body, and sets aria-busy on the <table>. Keep previous rows rendered so the layout doesn't jump.

booleanfalse
loadingLabel

Text announced by the loading spinner.

string"Loading"
stackBelow

Turns rows into stacked cards below this viewport width, labelling each value with its column header (data-label). While stacked, every part gets an explicit ARIA table role (table, rowgroup, row, columnheader, cell), because some browsers drop native table semantics when CSS changes a table's display. The header row is visually hidden but stays in the accessibility tree.

"sm""md"—
scrollLabel

Accessible name for the scroll region, used when the table overflows and has no Table.Caption, aria-label, or aria-labelledby.

string"Scrollable table"
className

Class name for the outer frame. Every other prop goes on the <table>.

string—
style

Inline style for the outer frame.

CSSProperties—
children

Table 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>).

Table.Row props
PropTypeDefault
selected

Shows the row as selected. Visual only: aria-selected is not valid on rows of a plain <table> (only inside role="grid" / treegrid), so the selected state is conveyed to assistive technology by the row's checked Table.SelectCell checkbox. Pair the two.

booleanfalse

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.

Table.HeaderCell props
PropTypeDefault
scope

Which 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)
sortable

Renders the header as a sort button.

booleanfalse
sortDirection

Current sort of this column. Sets aria-sort when not "none".

"ascending""descending""none""none"
onSort

Called when the sort button is pressed, with the suggested next direction (ascending from none or descending, descending from ascending).

(nextDirection: TableSortDirection) => void—
align

Horizontal alignment.

"start""center""end""start" ("end" when `numeric`)
numeric

Tabular, end-aligned numbers in the display font.

booleanfalse
truncate

Keeps content on one line and cuts it off with an ellipsis. Works best with layout="fixed" or a width. String content also gets a title tooltip; screen readers always read the full text.

booleanfalse
width

Column 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>).

Table.Cell props
PropTypeDefault
label

Column label shown beside the value when rows are stacked (stackBelow). Defaults to the matching header cell's text.

string—
align

Horizontal alignment.

"start""center""end""start" ("end" when `numeric`)
numeric

Tabular, end-aligned numbers in the display font.

booleanfalse
truncate

Keeps content on one line and cuts it off with an ellipsis. Works best with layout="fixed" or a width. String content also gets a title tooltip; screen readers always read the full text.

booleanfalse
width

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

Table.SelectCell props
PropTypeDefault
checkedRequired

Whether the row is selected.

boolean—
onCheckedChangeRequired

Called with the next checked state.

(checked: boolean) => void—
rowLabel

Readable name of the row, used for the checkbox's accessible name: "Select row {rowLabel}". Ignored when checkboxLabel is set.

string—
checkboxLabel

Full accessible name for the checkbox, overriding the "Select row" pattern.

string—
disabled

Prevents changing this row's selection.

booleanfalse

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.

Table.SelectAllCell props
PropTypeDefault
checkedRequired

Whether every row is selected.

boolean—
indeterminate

Whether some, but not all, rows are selected (mixed state).

booleanfalse
onCheckedChangeRequired

Called with the next checked state.

(checked: boolean) => void—
checkboxLabel

Accessible name for the checkbox.

string"Select all rows"
disabled

Prevents changing the selection.

booleanfalse

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.

Table.Empty props
PropTypeDefault
colSpan

Number of columns to span.

numberthe measured header column count
icon

Decorative icon above the message.

ReactNode—
heading

Bold heading, such as "No players yet".

ReactNode—
children

Supporting message.

ReactNode—
action

An 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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

36 passed · 0 failed · 29 not applicable · 10 to check by hand

Dark mode

Score 100

36 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

Keyboard
KeyAction
TabMoves through sort buttons, selection checkboxes and controls in cells.
EnterSpaceSorts by the focused column.
SpaceSelects or clears the focused row's checkbox.

Roles and states

Roles and states
ElementRoleStates and properties
<table>table<caption> names it
Header cellcolumnheader / rowheaderaria-sort on the sorted column
Selection checkboxcheckboxaria-label ("Select row …", "Select all")
Scrolling wrapperregionaria-label

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)