Skip to content
English

How it works

A card: no outer border, a muted 12px header over the card's only hairline, and rows with no lines between them. The checkbox is a real input, transparent and filling the cell, so a click anywhere in it counts; the visible 18px box and the stroke-drawn tick are decoration. The header box has three states: none, some (mixed) and all. Shift-click sets every row between the last click and this one to the new state. Selected rows are tinted with the accent. When rows are selected, an ink bar (text colour background) is laid over the header row to the right of the select-all box, so the card never changes height and no data row is covered. Selected ids outside the current rows are kept, so selection can span pages.

Use it for

  • Doing the same thing to many rows: approve expense claims, ship orders, archive projects.
  • Selecting a long run of rows: click the first, Shift-click the last.
  • Selecting across pages with a controlled selected list that survives paging.

Look elsewhere when

  • Rows with just one or two actions and no bulk need: put action buttons at the row end.
  • Choosing a single row: use row highlighting or a radio group.
  • Bulk actions that cannot be undone, such as bulk delete: follow them with a confirmation or an undo.

Usage

import { useState } from 'react'
import { SelectTable } from './SelectTable.jsx'

const columns = [
  { key: 'name', title: 'Submitted by' },
  { key: 'amount', title: 'Amount', width: 80, align: 'right', render: (r) => `$${r.amount}` },
]

const rows = [
  { id: 'e1', name: 'Mara Olsen', amount: 486 },
  { id: 'e2', name: 'Tomás Ortega', amount: 64 },
  { id: 'e3', name: 'Priya Raman', amount: 312, paid: true },
]

export function ExpenseClaims() {
  const [selected, setSelected] = useState([])
  const approve = (keys) => {
    // Call your API, then clear the selection
    setSelected([])
  }
  return (
    <SelectTable
      title="Expense claims"
      subtitle="November"
      columns={columns}
      rows={rows}
      rowKey={(r) => r.id}
      selected={selected}
      onSelectedChange={setSelected}
      isRowDisabled={(r) => r.paid === true} // paid claims cannot be selected
      rowLabel={(r) => `Select ${r.name}`}
      bulkActions={(keys) => (
        <button type="button" className="ds-selecttable__action ds-selecttable__action--primary" onClick={() => approve(keys)}>
          Approve
        </button>
      )}
    />
  )
}

Props

PropTypeDefaultWhat it does
columns{ key, title, width?, align?, render? }[]—Column definitions: key (also the default field to read), title, width, align and render for custom cells.
rowsobject[]—The data rows.
rowKey(row) => string | number—A unique id for each row; the selection is made of these values.
selected(string | number)[]—Controlled: the selected row ids. When omitted the component keeps its own.
defaultSelected(string | number)[][]Initial selection when uncontrolled.
onSelectedChange(keys) => void—Called when the selection changes. Keys follow row order; selected ids not in the current rows are kept at the front.
isRowDisabled(row) => boolean—Rows returning true cannot be selected: the checkbox is greyed and select-all and range selection skip them.
selectOnRowClickbooleantrueClicking a whole row toggles it. Buttons, links and inputs in the row do not (add data-no-select to custom elements).
bulkActions(selected, clear) => ReactNode—Buttons for the ink bulk bar. Give them the class ds-selecttable__action; add ds-selecttable__action--primary for the main one (accent filled) or ds-selecttable__action--danger for a destructive one.
rowLabel(row) => stringlabels.selectRow(index)Accessible name of each row's checkbox, such as (row) => `Select ${row.name}`.
emptyTextReactNode'No data'Text shown when there are no rows.
titleReactNode—Card title shown in the title row. A string title also names the table for screen readers when label is not given.
subtitleReactNode—Muted qualifier after the title, such as a period ("This week").
iconReactNode—Icon before the title, drawn in a tinted 32px rounded square. Decorative (aria-hidden).
actionsReactNode—Controls at the right end of the title row (buttons, a switch, a menu).
labelstring—Table name for screen readers (the <caption>). Defaults to title when title is a string.
labelsobject—Replaces built-in text (selectAll, selectRow, selectedCount, cleared, bulkActions, clearSelection). Shallow-merged over the English defaults.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root <div>.

Accessibility

  • Checkboxes are native inputs: Tab reaches each and Space toggles; the header one is named “Select all”, each row's by rowLabel; the mixed state uses indeterminate.
  • A live region announces changes such as “3 selected” and “Selection cleared”.
  • The bulk bar is visibility: hidden when nothing is selected; when it hides, focus returns to the header checkbox. The clear button is an icon with an accessible name.
  • Selection is not shown by colour alone: each checkbox is the state, and disabled rows are greyed with a not-allowed cursor.
  • On touch screens the header grows to 44px and the checkbox column to 48px.

Motion

Checking fills the box with the accent and pops it (0.8 → 1.12 → 1, 360ms spring); the tick draws with stroke-dashoffset 60ms later (240ms ease-out); the box shrinks to 0.9 while pressed. Row tint 160ms. The bulk bar rises 6px and grows from 0.97 with a spring over 240ms, and leaves in 160ms ease-in; the column titles under it fade. Reduced motion: no pop, no drawing, no slide.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

SelectTable.jsxselect-table.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Tables
Compare table comes with Pro. Its preview shows once you unlock it.
Data bar table comes with Pro. Its preview shows once you unlock it.