Tables
Lets people scan, sort, select and act on many records of the same kind.
A table is for comparing many records on the same properties. This page decides which controls a table carries, how selection and bulk actions work, and how a table behaves when it does not fit the screen.
The problem
Purchase orders, inspections and work orders come in dozens. People need to find one, compare several and act on a group of them without opening each. A table that only lists rows forces them to leave the page for every action. A table with every possible control buries the data.
Anatomy
| Part | Component | Job |
|---|---|---|
| Search | Input Group | Narrows the rows by text. |
| Table | Table | The rows, with sortable column headers and a selection column. |
| Selection | Checkbox | Chooses rows for a bulk action. |
| Bulk actions | Button | Act on every selected row, in a bar that shows the count. |
| Row actions | Dropdown Menu | Open, duplicate or archive a single row. |
| Status | State square and a word | Ink done, outline plain, grey off. One crimson square for the one row that is late. The outcome of a check can be a status Badge with an icon and a word. |
| Pagination | Pagination | Moves between pages and shows the range. |
| Page size | Select | Chooses how many rows a page holds. |
| Detail | Sheet | Shows the whole record without leaving the table. |
For the table component itself see Table and Data Table.
Blocks
Data table
tables-01 lists 24 purchase orders. Every column header sorts. A checkbox column selects rows, and the selection stays when you change page. When rows are selected, the bar above the table shows the count with Approve, Archive and Clear. Each row has an actions menu, and archiving shows a confirmation with Undo. Search narrows the rows and resets to the first page.
Choose it when people work through a list and act on several rows at once.
Records with a detail panel
tables-02 lists non-conformities. Pressing a row opens a sheet with the whole record and one action, close the non-conformity. A Columns menu shows and hides columns, and a toggle changes the row density between comfortable and compact.
Choose it when each row hides more than the columns can show, and people read records more than they act on groups.
Behaviour
States
- Default: rows separated by a hairline, no zebra stripes, no cell borders.
- Hover and focus: a tone step behind the row. The focused cell shows the focus ring.
- Selected: a darker tone step behind the row and a ticked checkbox. The header checkbox is ticked when every row on the page is selected, and mixed when some are.
- Sorted: the sorted column shows an arrow. Sorting applies to every row, not only the page.
- Empty after search: the table says what was searched and offers Clear search.
- Late row: the single crimson square. If several rows are late, mark none of them with crimson and use the word.
Responsive behaviour
| Width | Behaviour |
|---|---|
| 1280px and wider | All columns visible. Toolbar on one line. |
| 768px to 1279px | All columns visible. Hide the least important column with the Columns menu. |
| Below 768px | The table scrolls sideways inside its own container. The page never scrolls sideways. The toolbar stacks. Page numbers hide, Previous and Next stay. |
| 320px | Same as below 768px. Keep the first column, the one that names the row, as the first thing in view. |
Keyboard and focus
| Key | Action |
|---|---|
| Tab | Moves focus into the table, and out of it again. |
| Arrow Down | Moves to the same cell in the next row. |
| Arrow Right | Moves to the next cell in the row. |
| Space | Selects or clears the focused row, or presses the focused column header to sort. |
| Enter | Opens the detail of the focused row where the row has an action, or sorts the focused column. |
| Esc | Closes the row menu or the detail sheet. |
Closing the detail sheet returns focus to the row that opened it.
On a phone
A dense table stays compact on a phone: the selection checkboxes, the row actions, the pagination and the density toggle keep the shipped sizes, which meet the WCAG minimum. tables-01 puts pointer-coarse:touch-controls on the New order button only. tables-02 puts it on the detail sheet, where the person decides and closes the non-conformity. See Sizing.
Accessibility
- Give the table an accessible name with
aria-labeloraria-labelledby. - Mark the column that names a row as the row header, so a screen reader reads "PO-2417" before each cell.
- Give each row checkbox the row's name. The checkbox in the header selects the page, so name it for the page.
- An icon-only row action needs a name that includes the row:
Actions for PO-2417. - Announce the result count after search with
role="status", and the selection count in the bulk bar. - Sorting changes the order of rows without a page load. The sort direction is exposed on the column header.
Content
- Column headers are nouns in sentence case: Order, Supplier, Due, Total, Status.
- Right-align numbers and use tabular figures, so digits line up. Left-align text.
- Write status as a word beside the square: Approved, Waiting for approval, Late. Write an outcome as a word and an icon in a status badge: Passed, Failed. Never colour alone.
- Confirm a bulk action with a typed toast, as
tables-01does withtoast.successafter Approve orders. - Dates in the table are short: 9 Dec. Put the year in the detail.
- Bulk action labels name their object: Approve orders, not Apply.
Show how many rows are selected and name what each action will do to them.
Don’t show bulk actions with no count and no object. People cannot tell what Apply will change.
Install
pnpm dlx shadcn@latest add @silkware/tables-01pnpm dlx shadcn@latest add @silkware/tables-02