Skip to content

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

PartComponentJob
SearchInput GroupNarrows the rows by text.
TableTableThe rows, with sortable column headers and a selection column.
SelectionCheckboxChooses rows for a bulk action.
Bulk actionsButtonAct on every selected row, in a bar that shows the count.
Row actionsDropdown MenuOpen, duplicate or archive a single row.
StatusState square and a wordInk 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.
PaginationPaginationMoves between pages and shows the range.
Page sizeSelectChooses how many rows a page holds.
DetailSheetShows 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.

Open in a new tab

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.

Open in a new tab

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

WidthBehaviour
1280px and widerAll columns visible. Toolbar on one line.
768px to 1279pxAll columns visible. Hide the least important column with the Columns menu.
Below 768pxThe table scrolls sideways inside its own container. The page never scrolls sideways. The toolbar stacks. Page numbers hide, Previous and Next stay.
320pxSame as below 768px. Keep the first column, the one that names the row, as the first thing in view.

Keyboard and focus

KeyAction
TabMoves focus into the table, and out of it again.
Arrow DownMoves to the same cell in the next row.
Arrow RightMoves to the next cell in the row.
SpaceSelects or clears the focused row, or presses the focused column header to sort.
EnterOpens the detail of the focused row where the row has an action, or sorts the focused column.
EscCloses 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-label or aria-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-01 does with toast.success after 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.
3 orders selected
3 orders selected
Do

Show how many rows are selected and name what each action will do to them.

Don’t

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-01
pnpm dlx shadcn@latest add @silkware/tables-02