<!-- index: /slotted/llms.txt -->
# table

`data-ui="table"` · Semantic table with sorting, filters and selection.

## Import

```tsx
import {
  Table,
  TableBody,
  TableCaption,
  TableCell,
  TableColumnActions,
  TableColumnHeader,
  TableContent,
  TableDefaultsProvider,
  TableDetail,
  TableEmpty,
  TableExpander,
  TableFooter,
  TableGroupRow,
  TableHead,
  TableLoader,
  TableMark,
  TableRow,
  TableRowHeader,
  TableSelect,
  TableSelectAll,
  TableSort,
  TableSummary,
} from '@slotted/react';
```

## Minimal example

Example

```tsx
import {
  Table,
  TableBody,
  TableCaption,
  TableCell,
  TableColumnHeader,
  TableContent,
  TableHead,
  TableRow,
  TableRowHeader,
} from '@slotted/react/table';
import { Tag } from '@slotted/react/tag';

const USD = new Intl.NumberFormat('en-US', { currency: 'USD', style: 'currency' });

const TONE = {
  Delivered: 'success',
  'On hold': 'warning',
  Processing: 'accent',
  Shipped: 'secondary',
} as const;

const ORDERS = [
  {
    id: 'SO-10421',
    customer: 'Alfreds Futterkiste',
    warehouse: 'Reno',
    status: 'Shipped',
    total: 1240,
  },
  {
    id: 'SO-10422',
    customer: "Bon app'",
    warehouse: 'Columbus',
    status: 'Processing',
    total: 860.5,
  },
  {
    id: 'SO-10423',
    customer: 'Ernst Handel',
    warehouse: 'Savannah',
    status: 'On hold',
    total: 3410.25,
  },
  {
    id: 'SO-10424',
    customer: 'Folk och fä HB',
    warehouse: 'Reno',
    status: 'Delivered',
    total: 512,
  },
  {
    id: 'SO-10425',
    customer: 'QUICK-Stop',
    warehouse: 'Columbus',
    status: 'Shipped',
    total: 2088.9,
  },
] as const;

export default function TableBasic() {
  return (
    <Table columns={5}>
      <TableContent>
        <TableCaption>Orders placed today</TableCaption>
        <TableHead>
          <TableRow>
            <TableColumnHeader>Order</TableColumnHeader>
            <TableColumnHeader>Customer</TableColumnHeader>
            <TableColumnHeader>Warehouse</TableColumnHeader>
            <TableColumnHeader>Status</TableColumnHeader>
            <TableColumnHeader numeric>Total</TableColumnHeader>
          </TableRow>
        </TableHead>
        <TableBody>
          {ORDERS.map((order) => (
            <TableRow key={order.id} value={order.id}>
              <TableRowHeader text="nowrap">{order.id}</TableRowHeader>
              <TableCell>{order.customer}</TableCell>
              <TableCell>{order.warehouse}</TableCell>
              <TableCell>
                <Tag tone={TONE[order.status]}>{order.status}</Tag>
              </TableCell>
              <TableCell numeric>{USD.format(order.total)}</TableCell>
            </TableRow>
          ))}
        </TableBody>
      </TableContent>
    </Table>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div | yes |
| `scroll` | div | yes |
| `table` | table | yes |
| `caption` | caption | no |
| `head` | thead | no |
| `body` | tbody | yes |
| `summary` | tfoot | no |
| `footer` | div | no |
| `row` | tr | yes |
| `column-header` | th | no |
| `row-header` | th | no |
| `cell` | td | yes |
| `sort` | button | no |
| `column-actions` | span | no |
| `filter` | button | no |
| `filter-panel` | div | no |
| `filter-condition` | div | no |
| `filter-operator` | div | no |
| `filter-operand` | div | no |
| `filter-join` | div | no |
| `filter-search` | div | no |
| `filter-list` | div | no |
| `filter-option` | div | no |
| `filter-empty` | p | no |
| `filter-actions` | div | no |
| `selection` | th or td | no |
| `expander` | button | no |
| `mark` | span | no |
| `detail` | tr | no |
| `group-row` | tr | no |
| `group-header` | th | no |
| `group-content` | div | no |
| `group-start` | span | no |
| `group-end` | span | no |
| `empty` | td | no |
| `loader` | tbody | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `sort` | `TableSortDescriptor \| null` | — | Table | The column the rows are ordered by. Present means you own it. |
| `defaultSort` | `TableSortDescriptor \| null` | null | Table | The order an uncontrolled table starts in, read once |
| `value` | `readonly string[]` | — | Table | The chosen rows. Present means you own the selection. |
| `defaultValue` | `readonly string[]` | [] | Table | The rows an uncontrolled table starts with |
| `expanded` | `readonly string[]` | — | Table | The rows whose detail is open. Present means you own it. |
| `defaultExpanded` | `readonly string[]` | [] | Table | The details an uncontrolled table starts with |
| `variant` | `'plain' \| 'ruled' \| 'framed'` | ruled | Table | How much of a frame the set is given |
| `edges` | `'inset' \| 'flush'` | inset | Table | Whether the first and the last column keep the cell inset on their outer side. flush lines a plain or ruled table up with the heading around it, leaving the theme’s --slotted-table-edge-inset (0 unless set); a framed table ignores it. Sticky and selection columns keep their own offsets |
| `striped` | `boolean` | false | Table | A tinted ground on every second record |
| `guides` | `boolean \| 'branch'` | true | Table | A line per ancestor level beside the rows that name a parent, on the center of the expander one level up. branch draws a rail from the foot of the parent’s mark (TableMark, or the expander), a branch to each child and an elbow at the last, and keeps the marks of a level in one column |
| `expanderRoom` | `'auto' \| 'always'` | auto | Table | Under guides="branch", whether the marks of the top level keep the room of an expander before them. auto keeps it while a row of the table has one; always keeps it in a table where no row folds, so the marks of several tables, and of a table and its skeleton, stand in one column |
| `stickyHeader` | `boolean` | false | Table | Whether the header stays while the body scrolls |
| `stickyFooter` | `boolean` | false | Table | Whether the summary rows stay while the body scrolls. It pins the tfoot and not the footer bar, which never scrolls. |
| `stickyTo` | `'scroll' \| 'page'` | scroll | Table | What the header stays inside: this table own scroller, or whatever scrolls outside it. page releases the scroller, so the table stops scrolling sideways in its frame. |
| `options` | `readonly TableFilterOption[]` | [] | TableSetFilter | The values the column can be filtered to, each with an optional count of its own. With operand tags they are a datalist and the set a typed value must belong to; without them any value is admitted. |
| `operand` | `'list' \| 'tags'` | list | TableSetFilter | How the values are chosen: the search, the covering checkbox and the list, or tags-input holding the chosen values as chips. The descriptor is the same list either way. |
| `presets` | `readonly PickerPreset[]` | — | TableDateFilter, TableTimeFilter, TableDateTimeFilter | The application’s own ranges, each a label and a run, offered inside the range picker between draws. The descriptor still receives two ISO values. |
| `granularity` | `'hour' \| 'minute' \| 'second'` | minute | TableTimeFilter, TableDateTimeFilter | The last unit the picker writes, and the precision the engine compares at: a minute-precision operand matches every second of its minute. |
| `value` | `TextFilter \| NumberFilter \| DateFilter \| TimeFilter \| DateTimeFilter \| BooleanFilter \| SetFilter \| null` | null | Table*Filter | The descriptor the column is filtered by, typed as its own kind. Controlled when stated; defaultValue is the uncontrolled form, and onValueChange fires once, on Apply. |
| `operators` | `readonly FilterOperator[]` | the kind own list | Table*Filter | Narrows what the chooser offers, in the order given. defaultOperator picks the one the panel opens on. |
| `conditions` | `1 \| 2` | 2 | Table*Filter | How many conditions the panel offers. The second appears once the first is complete. |
| `renderOperand` | `(props: TableFilterOperandProps) => ReactNode` | — | Table*Filter | Replaces the field the table would have drawn, and keeps the draft, the chooser, the join, the actions and the announcements. |
| `searchThreshold` | `number` | 8 | TableSetFilter | How many values bring a search with them. searchable states it outright. |
| `cellAlign` | `'start' \| 'center' \| 'end'` | center | Table | Where every cell content sits in a row as tall as its tallest cell. A cell states blockAlign to answer differently. |
| `layout` | `'auto' \| 'fixed'` | auto | Table | Whether the browser sizes the columns from their content or from what you state |
| `selectionMode` | `'none' \| 'single' \| 'multiple'` | none | Table | How many records may be chosen at once |
| `columns` | `number` | 1 | Table | How many columns the spanning parts span |
| `loading` | `boolean` | false | Table | A refresh over rows already shown: aria-busy, and nothing moves |
| `messages` | `Partial<TableMessages>` | — | Table | Words laid over the language in force, key by key: selection, expansion, sort and every word of the column filters |
| `skeletonRows` | `number` | 5 | TableLoader | How many skeleton rows a first load draws |
| `totalRowCount` | `number` | — | TableContent | The size of the set behind a page, written as aria-rowcount |
| `scrollLabelledBy` | `string` | — | TableContent | The element that names the region instead, usually the caption |
| `value` | `string` | — | TableRow | The record key the selection and the expansion are held by |
| `level` | `number` | — | TableRow | How deep the row sits under the rows that fold it, from 0. The first cell that is not the selection is indented by this many steps, and a cell without an expander keeps its box as space |
| `parent` | `string` | — | TableRow | The value of the row whose expander folds this one. The row is not rendered while that row, or any row above it, is closed. |
| `disabled` | `boolean` | false | TableRow | A record the reader may not choose; it leaves the set the header covers |
| `rowIndex` | `number` | — | TableRow | The record position in the whole set, written as aria-rowindex |
| `current` | `boolean` | false | TableRow | The record open elsewhere on the page, a detail pane beside the table, written as aria-current |
| `visuallyHidden` | `boolean` | false | TableCaption | Keeps the caption as the accessible name of the table and draws nothing, for a table under a heading that already names it |
| `muted` | `boolean` | false | TableRow | Draws the row in the muted ink, for a record that is no longer active; the row stays selectable and pressable |
| `interactive` | `boolean` | true with onAction | TableRow | Paints the row as a thing the pointer presses |
| `onAction` | `(event) => void` | — | TableRow | A click anywhere in the row that lands on no control of its own; the first link or button in the row is the keyboard way in |
| `end` | `ReactNode` | — | TableGroupRow | What stands at the end of the band: the total or net of the group |
| `column` | `string` | — | TableColumnHeader, TableSort | The column key the sort descriptor names |
| `align` | `'start' \| 'center' \| 'end'` | start | the three cell parts | Which edge the value stands on, resolved logically |
| `numeric` | `boolean` | false | the three cell parts | Tabular figures, and the end edge unless align says otherwise |
| `blockAlign` | `'start' \| 'center' \| 'end'` | center | the three cell parts and both selection cells | Where this cell content sits in its row, overriding the table own cellAlign |
| `text` | `'wrap' \| 'truncate' \| 'nowrap'` | wrap | the three cell parts | What a value longer than its column does |
| `sticky` | `'start' \| 'end'` | start | the three cell parts and both selection cells | Which edge the column is pinned to while the table scrolls past it |
| `sticky` | `boolean` | false | TableGroupRow | Holds the band under the header while its rows scroll past |
| `stickyOffset` | `string` | 0 | the three cell parts and both selection cells | Where the pinned column stops, as a CSS length. Two columns pinned to the same edge need the second to state how wide the first is — beside a selection column that is --slotted-table-selection-size, which is 3rem. |
| `colSpan` | `number` | — | TableDetail, TableEmpty | How many columns the part spans, defaulting to the table own count |
| `render` | `(props) => ReactNode` | — | Table, TableRow, TableSort | Substitutes the rendered element, keeping every data attribute |
| `ref` | `Ref<HTMLElement>` | — | every part | Reaches the element, and focus() with it |
| `handleRef` | `RefObject<TableHandle>` | — | TableContent | scrollToRow(), overflowing() and refresh(): the three a prop cannot express |
| `useTable()` | `() => TableContextValue` | — | inside a Table | The sort, the selection and the words, for a part of your own |
| `TableDefaultsProvider` | `variant \| striped \| stickyHeader \| stickyFooter \| stickyTo \| layout \| selectionMode \| columns` | — | Application | Sets those once for everything below it; a prop on the table still wins |
| `scrollProps` | `ComponentPropsWithRef<'div'>` | — | TableContent | Reaches the scroller: a height, a ref, a scroll listener of your own |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onSortChange` | `(value: TableSortDescriptor \| null, request)` | The column and the direction the reader asked for, or null when the third press clears it. The request carries the reason — pointer, keyboard, clear or programmatic — and cancel(). |
| `onValueChange` | `(value: readonly string[], request)` | The chosen rows, in the collection order rather than the order they were pressed. The reason is select for a range or a select-all, clear when the set is emptied, pointer otherwise. |
| `onExpandedChange` | `(value: readonly string[], request)` | The rows whose detail is open, after the press that opened or closed one. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `variant` | `plain`, `ruled`, `framed` | `ruled` |
| `edges` | `inset`, `flush` | `inset` |
| `striped` | `true`, `false` | `false` |
| `stickyHeader` | `true`, `false` | `false` |
| `stickyFooter` | `true`, `false` | `false` |
| `stickyTo` | `scroll`, `page` | `scroll` |
| `layout` | `auto`, `fixed` | `auto` |
| `cellAlign` | `start`, `center`, `end` | `center` |
| `selectionMode` | `none`, `single`, `multiple` | `none` |
| `align` | `start`, `center`, `end` | `start` |
| `numeric` | `true`, `false` | `false` |
| `text` | `wrap`, `truncate`, `nowrap` | `wrap` |
| `sticky` | `start`, `end` | `start` |
| `blockAlign` | `start`, `center`, `end` | `center` |
| `expanderRoom` | `auto`, `always` | `auto` |
| `guides` | `true`, `false`, `branch` | `true` |

## Rules

- The role is table and not grid, and the difference is the whole boundary with data-grid. The APG says a table "is not an interactive widget. Thus, its cells are not focusable or selectable", so every control inside is its own tab stop and the family binds no key. Column resizing, virtualisation, multi-column sort and row activation all need the grid pattern and are deferred to the family that has it.
- Every role comes from the platform: table, thead, tbody, tfoot, tr, th and td already carry table, rowgroup, row, columnheader, rowheader and cell. The family writes none of them, and it writes no aria-labelledby either — a caption is the accessible name by the browser own rule, whether it is visible or visually hidden.
- scope="col" on a column header and scope="row" on a row header are what make a screen reader repeat the column name and the record name in each cell. They are the two attributes §12 of the feature guide asks for by name.
- aria-sort is written on the sorted header and removed from every other, because ARIA has no way to state a sort level and a second sorted column would be silent or a lie. The change is also announced politely with the column and the direction: a property that changes silently is a change no reader hears, and none of the six surveyed implementations says it.
- A row is not selectable under this role, so it carries no aria-selected. The state is painted with data-selected and announced by the checkbox that owns it — the division list-item recorded — and the header checkbox states in its own name how many rows it covers.
- aria-rowcount and aria-rowindex are written exactly when you state a total larger than the DOM, which is what the Grid and Table Properties practice requires: the pair exists to say the DOM is not the whole set. The practice warns that writing aria-rowindex on some rows and not others has devastating effects, so the family writes neither unless you state both.
- The scroller becomes a region with a tab stop and a name only while the table overflows, measured rather than assumed. A wide table with no tab stop is unreachable without a pointer — a WCAG 2.2 level A failure — and a tab stop on a table that fits is one a reader presses for nothing.
- The expander is the Disclosure pattern: a button with aria-expanded, and with aria-controls naming the detail row while it is open. A closed detail is not rendered at all, so nothing is announced that a reader cannot reach.
- A selected row is said by its ground and its ink together, and by the checkbox mark. R1 of this repository forbids the rail two families reached for, and in the high-contrast scheme every tone ground is the page own white — so the mark is what survives, which is where WCAG 2.2 SC 1.4.1 puts the requirement.

## Tokens

`--slotted-border-strong`, `--slotted-border-subtle`, `--slotted-border-width-thin`, `--slotted-control-font-family`, `--slotted-control-font-size-md`, `--slotted-control-gap-md`, `--slotted-control-height-md`, `--slotted-control-icon-size-md`, `--slotted-control-padding-inline-md`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-foreground`, `--slotted-duration-short`, `--slotted-easing-standard`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-size-xs`, `--slotted-font-weight-medium`, `--slotted-font-weight-regular`, `--slotted-font-weight-semibold`, `--slotted-ground`, `--slotted-line-height-md`, `--slotted-radius-md`, `--slotted-radius-sm`, `--slotted-shadow-xs`, `--slotted-space-1`, `--slotted-space-2`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-space-9`, `--slotted-surface`, `--slotted-table-border-color`, `--slotted-table-border-color-strong`, `--slotted-table-border-width`, `--slotted-table-branch-size`, `--slotted-table-caption-surface`, `--slotted-table-cell-padding-block`, `--slotted-table-cell-padding-inline`, `--slotted-table-color`, `--slotted-table-color-muted`, `--slotted-table-column-actions-size`, `--slotted-table-control-radius`, `--slotted-table-edge-inset`, `--slotted-table-font-family`, `--slotted-table-font-size`, `--slotted-table-gap`, `--slotted-table-group-color`, `--slotted-table-group-sticky-offset`, `--slotted-table-group-surface`, `--slotted-table-guide-color`, `--slotted-table-header-backdrop-filter`, `--slotted-table-header-surface`, `--slotted-table-header-surface-hover`, `--slotted-table-icon-size`, `--slotted-table-mark-child-size`, `--slotted-table-mark-size`, `--slotted-table-radius`, `--slotted-table-row-color-selected`, `--slotted-table-row-min-block-size`, `--slotted-table-row-surface-current`, `--slotted-table-row-surface-hover`, `--slotted-table-row-surface-selected`, `--slotted-table-row-surface-selected-hover`, `--slotted-table-row-surface-stripe`, `--slotted-table-selection-size`, `--slotted-table-shadow`, `--slotted-table-sticky-inset`, `--slotted-table-sticky-offset`, `--slotted-table-sticky-offset-end`, `--slotted-table-sticky-surface`, `--slotted-table-surface`, `--slotted-table-tree-indent`, `--slotted-target-comfortable`, `--slotted-target-min`, `--slotted-text`, `--slotted-text-muted`, `--slotted-tone-accent-subtle-hover`, `--slotted-tone-accent-surface`, `--slotted-tone-accent-text`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`, `--slotted-z-index-sticky`

## Examples

See [table.examples.md](./table.examples.md).
