Table

A semantic HTML table for displaying structured data.

Import

import { Table } from '@matix/components/table';

Usage

InvoiceStatusMethodAmount
INV001PaidCredit Card$250.00
INV002PendingPayPal$150.00
INV003UnpaidBank Transfer$350.00

Multi-Select

Table renders the highlight; useRowSelection from @matix/components/row-selection supplies the interaction. Add a Checkbox column for an explicit affordance — the highlight alone is easy to miss, and the header checkbox doubles as select-all.

NameArtistKindActions
Blue MondayNew OrderSong
TeardropMassive AttackSong
Midnight CityM83Song
Gold LionYeah Yeah YeahsSong
AvalonRoxy MusicAlbum
Late Night TapesVariousPlaylist
Pink MoonNick DrakeSong
ProtectionMassive AttackAlbum

Gestures

Where the pointer gestures live is set by trigger.

trigger: 'cell' confines them to the checkbox column, which leaves the rest of the row free for its own clicks. A press there reads as ticking a box: it toggles that row, so pressing it again deselects, and it never clears the others.

Gesture in the checkbox columnResult
ClickToggle that row; click again to deselect
Shift-clickAdd the range from the anchor
Press and dragPaint the pressed row's new state down the column
Click the header checkboxSelect all, or clear if any are selected

trigger: 'row' (the default) makes the whole row the target and follows Finder instead, where a plain click replaces the selection.

Gesture on the rowResult
ClickSelect that row only
Cmd-click / Ctrl-clickAdd or remove one row
Shift-clickSelect the range from the anchor
Cmd-Shift-clickAdd that range to the selection
Press and dragSweep a range; drag back to shrink it

The keyboard works the same under both, because the row keeps focus either way.

KeyResult
Arrow up / downMove the selection
Shift-arrowExtend the selection
Cmd-ASelect all
EscapeClear

The hook keeps no markup of its own. getTableProps() sets the grid role, getRowProps(id) supplies selected and the roving tabIndex, and getSelectionCellProps(id) carries the pointer gestures when trigger is cell — so Table stays a server component and ships no JavaScript of its own.

Text selection is handled differently per trigger. A row trigger makes the whole table a drag surface, so getTableProps() also sets selectable, which turns text selection off across the table. A cell trigger leaves the table selectable — cell text stays highlightable and copyable — and suppresses selection only for the length of a drag in the checkbox column.

Checkbox column

getCheckboxProps(id) drives a row checkbox and getHeaderCheckboxProps() drives the header one. The header checkbox is checked when every row is selected and aria-checked="mixed" when only some are; clicking it selects all, or clears as soon as anything is selected. That makes a separate "select all" button unnecessary.

A row checkbox is additive on purpose: clicking one toggles that row and leaves the rest alone, which is what a checkbox implies. Shift-clicking one adds the anchor range instead of replacing the selection.

<Table.Header>
  <Checkbox {...selection.getHeaderCheckboxProps()} aria-label="Select all tracks" />
</Table.Header>

<Table.Cell>
  <Checkbox {...selection.getCheckboxProps(track.id)} aria-label={`Select ${track.name}`} />
</Table.Cell>

Give each checkbox an aria-label; the control has no visible text of its own. In single mode there is nothing to select all of, so leave the header checkbox out.

Clickable content inside a selectable row

A press that starts on something which owns its own click never selects the row. Buttons, links with an href, form fields and anything with a button, link, checkbox, switch, menuitem or tab role are recognised already. Mark a custom widget with data-row-interactive:

<Table.Cell>
  <span data-row-interactive>
    <MyCustomToggle />
  </span>
</Table.Cell>

Secondary and middle clicks are left to the platform, so context menus and open-in-new-tab keep working.

Single select

NameArtist
Blue MondayNew Order
TeardropMassive Attack
Midnight CityM83
Gold LionYeah Yeah Yeahs
AvalonRoxy Music

single selects one row per click and turns off Shift, Cmd and drag. none disables selection while leaving the call site in place.

Controlled selection

Pass value and onValueChange to own the state — that is how the DataTable integration hands it to TanStack.

const [selected, setSelected] = useState<readonly string[]>([]);

const selection = useRowSelection({ rowIds, value: selected, onValueChange: setSelected });

useRowSelection

OptionTypeDefaultDescription
rowIdsreadonly string[]—Row ids in display order; ranges and arrows follow it
mode'none' | 'single' | 'multiple''multiple'Which gestures are live
trigger'row' | 'cell''row'Where the pointer gestures live
valuereadonly string[]—Controlled selection
defaultValuereadonly string[][]Initial uncontrolled selection
onValueChange(ids: readonly string[]) => void—Fires on every change
ResultTypeDescription
selectedreadonly string[]Selected ids, in selection order
isSelected(id: string) => booleanMembership test
getTableProps() => objectSpread on Table
getRowProps(id: string) => objectSpread on Table.Row
getSelectionCellProps(id: string) => objectSpread on the checkbox Table.Cell; carries the gestures when trigger is cell
getCheckboxProps(id: string) => objectSpread on a Checkbox in a row
getHeaderCheckboxProps() => objectSpread on a Checkbox in the header row
clear() => voidDeselect everything
selectAll() => voidSelect every row in rowIds

Selection is reported through aria-multiselectable on the grid and aria-selected on each row. One row stays in the tab order, and the arrow keys move from there.

Sortable Headers

INV001PaidCredit Card
INV002PendingPayPal
INV003UnpaidBank Transfer
InvoiceStatusAmount
INV001Paid$250.00
INV002Pending$150.00
INV003Unpaid$350.00
Total$750.00

Selectable Rows

Use the selected prop to highlight rows.

<Table>
  <Table.Head>
    <Table.Row>
      <Table.Header>Name</Table.Header>
      <Table.Header>Email</Table.Header>
    </Table.Row>
  </Table.Head>
  <Table.Body>
    <Table.Row selected>
      <Table.Cell>Alice</Table.Cell>
      <Table.Cell>alice@example.com</Table.Cell>
    </Table.Row>
    <Table.Row>
      <Table.Cell>Bob</Table.Cell>
      <Table.Cell>bob@example.com</Table.Cell>
    </Table.Row>
    <Table.Row selected>
      <Table.Cell>Carol</Table.Cell>
      <Table.Cell>carol@example.com</Table.Cell>
    </Table.Row>
  </Table.Body>
</Table>

With Caption

<Table caption="Team members as of March 2026">
  <Table.Head>
    <Table.Row>
      <Table.Header>Name</Table.Header>
      <Table.Header>Department</Table.Header>
    </Table.Row>
  </Table.Head>
  <Table.Body>
    <Table.Row>
      <Table.Cell>Alice</Table.Cell>
      <Table.Cell>Engineering</Table.Cell>
    </Table.Row>
    <Table.Row>
      <Table.Cell>Carol</Table.Cell>
      <Table.Cell>Marketing</Table.Cell>
    </Table.Row>
  </Table.Body>
</Table>

Scrolling

Table always renders inside a horizontal scroll container, so a wide table scrolls inside its own box and does not widen the page. contained={false} removes only the border and the surface. The scroll container is positioned, so absolutely positioned content in a cell, such as VisuallyHidden, stays inside it.

Custom Styles

import * as stylex from '@stylexjs/stylex';

const custom = stylex.create({
  compact: { fontSize: '0.85rem' },
});

<Table sx={custom.compact}>
  <Table.Head>
    <Table.Row>
      <Table.Header>Key</Table.Header>
      <Table.Header>Value</Table.Header>
    </Table.Row>
  </Table.Head>
  <Table.Body>
    <Table.Row>
      <Table.Cell>NODE_ENV</Table.Cell>
      <Table.Cell>production</Table.Cell>
    </Table.Row>
  </Table.Body>
</Table>;

Restyling headers

Headers read five CSS custom properties, each with the default as its fallback. Set them on the table, or anywhere above it, to reshape every header at once — an uppercase band, for example:

const banded = stylex.create({
  head: {
    '--mtx-table-head-bg': 'var(--mtx-colors-bgSubtle)',
    '--mtx-table-header-color': 'var(--mtx-colors-fgMuted)',
    '--mtx-table-header-size': '0.75rem',
    '--mtx-table-header-case': 'uppercase',
    '--mtx-table-header-tracking': '0.05em',
  },
});

<Table sx={banded.head}>…</Table>;
PropertyDefault
--mtx-table-head-bgtransparent
--mtx-table-header-colorfgBase
--mtx-table-header-sizesm
--mtx-table-header-casenone
--mtx-table-header-trackingnormal

API Reference

Table

PropTypeDefaultDescription
containedbooleantrueDraws a border, a surface, and rounded corners around the scroll container
captionReactNode—Table caption for accessibility
sxStyleXStyles—StyleX style override
childrenReactNode—Table sections (Head, Body, Foot)

Table.Row

PropTypeDefaultDescription
hoverablebooleantrueHighlight row on hover
selectedbooleanfalseApply selected background
selectablebooleanfalseOn Table: suppress text selection so a drag selects rows. getTableProps() sets it
sxStyleXStyles—StyleX style override
styleCSSProperties—Dynamic computed values only (e.g. virtualizer transform) — use sx for everything else
childrenReactNode—Row cells

Table.Header

PropTypeDefaultDescription
sortablebooleanfalseVisual only: pointer cursor and hover color. Add the button and aria-sort yourself
sxStyleXStyles—StyleX style override
childrenReactNode—Header label

Table.Cell

PropTypeDefaultDescription
sxStyleXStyles—StyleX style override
styleCSSProperties—Dynamic computed values only — use sx for everything else
childrenReactNode—Cell content

All native <td> attributes are forwarded.

Table.Head / Table.Body / Table.Foot

Semantic wrappers (<thead>, <tbody>, <tfoot>). Accept children and sx. Table.Body also accepts style for dynamic computed values (e.g. a virtualizer's total height).

Accessibility

  • Renders semantic <table>, <thead>, <tbody>, <tfoot>, <tr>, <th>, and <td> elements.
  • When caption is provided, it renders a <caption> element for screen readers.
  • sortable on Table.Header is visual only. For a sortable column, put a <button> inside the header and set aria-sort on Table.Header. DataTable does this for you.
  • selected on Table.Row is a visual tint. Screen readers ignore aria-selected on rows of a static table, so give each row a labelled Checkbox (for example "Select row Ada Lovelace").

This is an RSC-safe component — it ships no JavaScript to the browser.