Table
A semantic HTML table for displaying structured data.
Import
import { Table } from '@matix/components/table';Usage
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV001 | Paid | Credit Card | $250.00 |
| INV002 | Pending | PayPal | $150.00 |
| INV003 | Unpaid | Bank 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.
| Name | Artist | Kind | Actions | |
|---|---|---|---|---|
| Blue Monday | New Order | Song | ||
| Teardrop | Massive Attack | Song | ||
| Midnight City | M83 | Song | ||
| Gold Lion | Yeah Yeah Yeahs | Song | ||
| Avalon | Roxy Music | Album | ||
| Late Night Tapes | Various | Playlist | ||
| Pink Moon | Nick Drake | Song | ||
| Protection | Massive Attack | Album |
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 column | Result |
|---|---|
| Click | Toggle that row; click again to deselect |
| Shift-click | Add the range from the anchor |
| Press and drag | Paint the pressed row's new state down the column |
| Click the header checkbox | Select 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 row | Result |
|---|---|
| Click | Select that row only |
| Cmd-click / Ctrl-click | Add or remove one row |
| Shift-click | Select the range from the anchor |
| Cmd-Shift-click | Add that range to the selection |
| Press and drag | Sweep a range; drag back to shrink it |
The keyboard works the same under both, because the row keeps focus either way.
| Key | Result |
|---|---|
| Arrow up / down | Move the selection |
| Shift-arrow | Extend the selection |
| Cmd-A | Select all |
| Escape | Clear |
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
| Name | Artist |
|---|---|
| Blue Monday | New Order |
| Teardrop | Massive Attack |
| Midnight City | M83 |
| Gold Lion | Yeah Yeah Yeahs |
| Avalon | Roxy 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
| Option | Type | Default | Description |
|---|---|---|---|
rowIds | readonly 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 |
value | readonly string[] | — | Controlled selection |
defaultValue | readonly string[] | [] | Initial uncontrolled selection |
onValueChange | (ids: readonly string[]) => void | — | Fires on every change |
| Result | Type | Description |
|---|---|---|
selected | readonly string[] | Selected ids, in selection order |
isSelected | (id: string) => boolean | Membership test |
getTableProps | () => object | Spread on Table |
getRowProps | (id: string) => object | Spread on Table.Row |
getSelectionCellProps | (id: string) => object | Spread on the checkbox Table.Cell; carries the gestures when trigger is cell |
getCheckboxProps | (id: string) => object | Spread on a Checkbox in a row |
getHeaderCheckboxProps | () => object | Spread on a Checkbox in the header row |
clear | () => void | Deselect everything |
selectAll | () => void | Select 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
| INV001 | Paid | Credit Card |
| INV002 | Pending | PayPal |
| INV003 | Unpaid | Bank Transfer |
With Footer
| Invoice | Status | Amount |
|---|---|---|
| INV001 | Paid | $250.00 |
| INV002 | Pending | $150.00 |
| INV003 | Unpaid | $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>;| Property | Default |
|---|---|
--mtx-table-head-bg | transparent |
--mtx-table-header-color | fgBase |
--mtx-table-header-size | sm |
--mtx-table-header-case | none |
--mtx-table-header-tracking | normal |
API Reference
Table
| Prop | Type | Default | Description |
|---|---|---|---|
contained | boolean | true | Draws a border, a surface, and rounded corners around the scroll container |
caption | ReactNode | — | Table caption for accessibility |
sx | StyleXStyles | — | StyleX style override |
children | ReactNode | — | Table sections (Head, Body, Foot) |
Table.Row
| Prop | Type | Default | Description |
|---|---|---|---|
hoverable | boolean | true | Highlight row on hover |
selected | boolean | false | Apply selected background |
selectable | boolean | false | On Table: suppress text selection so a drag selects rows. getTableProps() sets it |
sx | StyleXStyles | — | StyleX style override |
style | CSSProperties | — | Dynamic computed values only (e.g. virtualizer transform) — use sx for everything else |
children | ReactNode | — | Row cells |
Table.Header
| Prop | Type | Default | Description |
|---|---|---|---|
sortable | boolean | false | Visual only: pointer cursor and hover color. Add the button and aria-sort yourself |
sx | StyleXStyles | — | StyleX style override |
children | ReactNode | — | Header label |
Table.Cell
| Prop | Type | Default | Description |
|---|---|---|---|
sx | StyleXStyles | — | StyleX style override |
style | CSSProperties | — | Dynamic computed values only — use sx for everything else |
children | ReactNode | — | 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
captionis provided, it renders a<caption>element for screen readers. sortableonTable.Headeris visual only. For a sortable column, put a<button>inside the header and setaria-sortonTable.Header.DataTabledoes this for you.selectedonTable.Rowis a visual tint. Screen readers ignorearia-selectedon rows of a static table, so give each row a labelledCheckbox(for example "Select row Ada Lovelace").
This is an RSC-safe component — it ships no JavaScript to the browser.