Data display
Table selection
A checkbox column for a data table
Service
Environment
Duration
auth-service
production
74s
billing-api
production
92s
edge-gateway
production
36s
media-proxy
development
129s
reports-worker
staging
211s
search-index
staging
148s
nothing chosen of 6
Usage
import {
Table,
TableBody,
TableHeader,
TableRow,
TableSelectionCell,
TableSelectionHeader,
TableViewport,
useTable,
} from "@gpuixui/data";
const table = useTable({ rows: files, keyOf: (row) => row.id, columns });
<Table height={320} aria-label="Files">
<TableViewport>
<TableHeader>
<TableRow>
<TableSelectionHeader
checked={table.allSelected}
indeterminate={table.someSelected}
onCheckedChange={table.setAllSelected}
disabled={table.rows.length === 0}
/>
<TableHeaderCell width={260}>Name</TableHeaderCell>
</TableRow>
</TableHeader>
<TableBody>
{table.rows.map((file) => (
<TableRow key={file.id} selected={table.isSelected(file.id)}>
<TableSelectionCell
checked={table.isSelected(file.id)}
onCheckedChange={() => table.toggleSelection(file.id)}
label={`Select ${file.name}`}
/>
<TableCell width={260}>{file.name}</TableCell>
</TableRow>
))}
</TableBody>
</TableViewport>
</Table>;API
TableSelectionHeader
| Prop | Type | Default | Consequence |
|---|---|---|---|
checked | boolean | — | whether every visible record is chosen |
indeterminate | boolean | false | paints a dash when only some visible records are chosen |
onCheckedChange | (selected: boolean) => void | — | the box's next state: choose every visible record, or clear the set |
label | string | Select every row | the box's accessible name |
width | number | 40 | the track width; the body box must match it |
disabled | boolean | false | refuses the press |
testId | string | — | the box's id; the header cell is ${testId}-cell and its target ${testId}-target |
A blank label is the documented default Select every row, not an unnamed
box: a default only covers an absent prop, and an i18n row with a missing
translation answers "" (src/behaviour/surface-a11y.test.tsx).
TableSelectionCell
| Prop | Type | Default | Consequence |
|---|---|---|---|
checked | boolean | — | whether this record is chosen |
onCheckedChange | (selected: boolean) => void | — | the box's next state; a controlled table flips the record's membership |
label | string | Select this row | the record's accessible name, e.g. Select file-001.ts; a blank name reads as the default |
width | number | 40 | the track width; the header box must match it |
disabled | boolean | false | refuses the press |
testId | string | — | the box's id; the cell is ${testId}-cell and its target ${testId}-target |
A row box's name is content: a record restored without its title interpolates
Select and a saved label answers "". A blank or whitespace name reads as
the documented Select this row rather than leaving the box unnamed — the same
rule the header box follows (src/behaviour/surface-a11y.test.tsx).
Edit this page on GitHubpackages/data/docs/table-selection.mdx