Table
Rows of data that compare along columns: members, invoices, deployments. Rows run edge to edge with a divider under each, header text is secondary, and a body row takes the neutral hover overlay. Cells hold any component: an Avatar and a name, a Badge, a Checkbox to pick the row, a DropdownMenu of row actions. Headers can sort, a TableToolbar above and below holds search, actions, the count and Pagination, and TableEmpty says when there are no rows. TableSelection adds row picking: a checkbox per row, one in the header that follows them, and a bar that counts and names the picked rows.
Preview
Usage
When to use
- A list of records the user compares along columns: members, invoices, deployments.
- Numbers that line up down a column, such as amounts or counts.
- Rows the user picks and then acts on together, such as removing several members, with TableSelection.
When not to use
- A single list of items with one or two lines each. Use a list of rows instead.
- A grid of cards, such as projects with images. Use Card.
- Layout. Use flex or grid classes.
Platform support
What each platform has, from the spec. A selected platform is highlighted.
| Name | Web | iOS | Android | Note |
|---|---|---|---|---|
| align | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| numeric | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| fit | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| sortDirection | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| onSort | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| selected | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| colSpan | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| defaultValue | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| value | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| onValueChange | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| label | Yes | Yes | Yes | |
| max | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| pending | Yes | Yes | Yes | |
| pendingLabel | Yes | Yes | Yes | |
| isEmpty | No | Yes | Yes | Only on iOS, Android. |
| selectionMode | No | Yes | Yes | Only on iOS, Android. |
| content | No | Yes | Yes | Only on iOS, Android. |
| empty | No | Yes | Yes | Only on iOS, Android. |
| selectionBar | No | Yes | Yes | Only on iOS, Android. |
| value of keyboard: Tab | Yes | Deferred | Deferred | |
| value of keyboard: Enter, Space | Yes | Deferred | Deferred |
Variants
align
Set on TableHead and TableCell. Where the content sits in the cell. end for numbers, center only for short status marks.
sortDirection
Set on a sortable TableHead. How the table is sorted by this column; sets aria-sort and the caret.
Examples
Invoices
Members
Rows picked with TableSelection: the header checkbox follows the rows, and the bar above counts and names the picked ones, with the actions on them. Search and an action above the table, a sortable name, an Avatar and an email in one cell, a Badge, row actions at the end, the count with Pagination below.
Many rows picked
Past three names the bar shows the rest as a count. max on TableSelectionBar changes how many names show.
No results
Next page loading
The user asked for page 2, which is still loading: page 1 stays, dimmed and marked busy. In an app, pending is the isPending of the transition that changes the page.
Do and don't
Do
- Use numeric on every cell of a number column, the header too.
- Put the table on a surface with its own edge (a Card, a page section); the table has none.
- Name it with a caption, or aria-label when a heading above says what it is.
- Put search and the main action in a TableToolbar above the table, and the count with Pagination in one below.
- Use fit for a Checkbox column and an actions column, so the data columns get the width.
- For rows the user picks and then acts on together, wrap the table in TableSelection; it keeps the header checkbox, the rows and the bar in step.
- Put the actions on the picked rows (Export, Delete) in TableSelectionBar, as sm buttons.
- When a page, sort or filter loads from the server, change it in a transition (useTransition) and pass isPending as pending: the current rows stay until the next ones arrive. Use Skeleton rows only for the first load.
Don't
- Don't wrap each row in a Card; rows are the layout.
- Don't center text columns; start-align them.
- Don't use a table for layout or for a single list of items.
- Don't wire Checkbox cells by hand when TableSelection fits; the header checkbox and the bar drift out of step.
- Don't empty the table or swap the rows for a spinner while the next page loads; the layout jumps and the user loses their place.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| align | enum | start | center | end | start | Set on TableHead and TableCell. Where the content sits in the cell. end for numbers, center only for short status marks. Not generated for iOS and Android. |
| numeric | boolean | - | false | Set on TableHead and TableCell. A number column: end-aligned, mono, tabular figures, so digits line up. Not generated for iOS and Android. |
| fit | boolean | - | false | Set on TableHead and TableCell. The column takes only the room its content needs: a Checkbox, a row's actions. Not generated for iOS and Android. |
| sortDirection | enum | none | ascending | descending | none | Set on a sortable TableHead. How the table is sorted by this column; sets aria-sort and the caret. Not generated for iOS and Android. |
| onSort | function | - | - | Set on TableHead. Makes the header a button that sorts by the column. Sort the rows yourself, then set sortDirection. Not generated for iOS and Android. |
| selected | boolean | - | false | Set on TableRow. The row is picked with its Checkbox: the muted accent fill. Not generated for iOS and Android. |
| colSpan | number | - | - | Set on TableEmpty. How many columns the table has, so the row spans them all. Not generated for iOS and Android. |
| defaultValue | string | - | - | Set on TableSelection. Values of the rows picked on first render, as an array: ["ada"]. Each value is a TableRowSelect's value. Not generated for iOS and Android. |
| value | string | - | - | Set on TableSelection: the picked values as an array, when you control them. Pair it with onValueChange. TableRowSelect takes one value, its row's id. Not generated for iOS and Android. |
| onValueChange | function | - | - | Set on TableSelection. Called with the new array of picked values. Not generated for iOS and Android. |
| label | string | - | - | Set on TableRowSelect, with its value. The row's name: TableSelectionBar shows it, and it names the checkbox "Select <label>". On native, set on Table: the name of the list of records for screen readers, such as Customers. |
| max | number | - | 3 | Set on TableSelectionBar. How many names show before the rest becomes +N. Not generated for iOS and Android. |
| pending | boolean | - | false | Table: the next page, sort or filter is still loading. Change it in a transition (useTransition) so the current rows stay, and pass its isPending: the rows dim to opacity-pending and the table is marked aria-busy instead of going blank. |
| pendingLabel | string | - | Loading | Table: read by screen readers in a polite status while pending. |
| isEmpty | boolean | - | false | Native only, on Table. There are no rows to show, or none match: the empty slot takes the place of the rows, so the region keeps its place. Only on iOS, Android. |
| selectionMode | boolean | - | false | Native only, on Table. Rows are being picked. The selection bar is pinned above the bottom inset while it is on, and the rows grow room under it so the last one stays reachable. Pass it to the List as well, so each row shows its checkbox. Only on iOS, Android. |
| content required | node | - | - | Native only, on Table. The rows: a List with variant cards, one ListItem per record. Only on iOS, Android. |
| empty required | node | - | - | Native only, on Table. What shows in place of the rows while isEmpty is on, usually an EmptyState with a way out such as clearing the search. Only on iOS, Android. |
| selectionBar | node | - | - | Native only, on Table. The content of the selection bar while selectionMode is on: the count, Select all, the app's actions and Clear selection. The Table draws the surface and pins it. Only on iOS, Android. |
Slots
| Name | Required | Description |
|---|---|---|
| toolbar | no | TableToolbar above the table (search, filters, TableActions with buttons) and one below it (the count, TableActions with Pagination). |
| header | no | TableHeader with one TableRow of TableHead cells. |
| body | yes | TableBody with one TableRow per item. |
| caption | no | TableCaption, or aria-label on Table. |
| cells | no | Any component in a TableCell: Avatar with a name, Badge, Checkbox in a fit cell, a DropdownMenu of row actions in a fit cell at the end. |
| empty | no | TableEmpty in TableBody when there are no rows. |
| selection | no | TableSelection around the bar, the toolbars and the table, with TableSelectAll in the header's first fit cell, a TableRowSelect in each row's, and TableSelectionBar above the toolbar. Children of the bar are the app's actions on the picked rows (Export, Delete). |
Anatomy
| Part | Description |
|---|---|
| root | Table: a full-width table, 14px primary text, inside a container that scrolls sideways. |
| header | TableHeader: the header rows. They don't highlight on hover. |
| row | TableRow: a row with a divider under it and the neutral hover overlay. The last body row has no divider. selected fills it with the muted accent and its strong text color. |
| head | TableHead: a header cell, the md control height, 14px medium secondary text on one line. |
| cell | TableCell: a data cell, px-md py-sm, that holds text or any component. align sets start, center or end; numeric sets mono, tabular figures and end; fit shrinks the column to its content. |
| footer | TableFooter: totals on the sunken fill, medium text, a divider above. |
| caption | TableCaption: the name of the table, under it, 14px secondary text. |
| sort | With onSort: a button in the header cell with the header's text and a caret, primary text on hover, a size-target-min hit area. |
| icon | The sort caret: Tabler ChevronUpDown, CaretUp or CaretDown, 16px, secondary. |
| empty | TableEmpty: one row across colSpan columns, 14px secondary text, centered, py-2xl. |
| toolbar | TableToolbar: a row above or below the table, gap-sm, that wraps: a search Input, filters, the count of results. |
| actions | TableActions: the end of a toolbar, gap-sm: buttons that act on the table, or Pagination. |
| selection | TableSelection: a column (gap-md) around the bar, the toolbars and the table. Holds the picked rows and announces their count in a status region. |
| selectAll | TableSelectAll: the Checkbox in the header's fit cell. On when every row on screen is picked, partly on when some are. |
| rowSelect | TableRowSelect: the Checkbox in a row's fit cell, named "Select <label>". A checked one paints its row with the muted accent. |
| selectionBar | TableSelectionBar: shows only while a row is picked. The count, up to max names then +N, Select all, the app's actions, Clear selection. Border, radius-container, surface fill. On native the Table draws it, pinned above the bottom inset and the safe area with a gap of spacing-md, and the app fills it. |
| body | The body rows. With pending they stay on screen and dim to opacity-pending (duration-medium); the container is marked aria-busy, with a polite status next to it. |
Accessibility
Role: table
| Keys | Action |
|---|---|
| Tab | Moves through the sort buttons in the headers and the controls inside cells; the table itself is not focusable. |
| Enter, Space | On a sortable header, sorts by that column. |
- A native table: screen readers read each cell with its column header. TableHead sets scope="col" by default; set scope="row" on a header cell that names its row.
- Name the table with a TableCaption, or aria-label or aria-labelledby when the name is a heading above it.
- A wide table scrolls sideways inside its container instead of widening the page.
- A sortable header is a button inside the header cell; the cell carries aria-sort (ascending or descending) only for the column the table is sorted by.
- Pick rows with a Checkbox in a fit cell, named for its row (Select Ada Lovelace); a header Checkbox picks every row. selected only paints the row: the Checkbox tells screen readers.
- Give an icon-only actions button a name with the row in it: Actions for Ada Lovelace.
- TableEmpty is one row across every column, so the table still has its headers when nothing matches.
- TableSelectAll is a mixed checkbox: aria-checked is mixed while some rows are picked. A press then picks the rest; a press when all are picked clears them.
- TableSelection keeps a status region that reads the count ("2 of 5 rows selected") whenever it changes.
- Select all and Clear selection go away once pressed, so focus moves first: to Clear selection after Select all, to the header checkbox after Clear selection.
- Native: a phone never shows a multi-column grid. Table is a list of records (a List with variant cards), so each record reads as one row: the title, then the supporting line and the status Badge. The region is named by label.
- Native: while pending the rows stay on screen at opacity-pending, the region reads pendingLabel as its value and a polite announcement says it once. Reduce motion makes the dim instant.
- Native: while selectionMode is on the selection bar sits above the bottom inset (and the safe area), and the rows keep room under it. A row is a checkbox named by its title, and the bar says how many are picked.
Install
npx werewolf-ui add tableRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.