Usage
Hook that returns a TablePlugin implementing row selection with checkboxes, select-all, and aria-selected. Uses React Context for independent checkbox re-renders.
tsimport {useTableSelection} from '@astryxdesign/core/Table'
Parameters
| Param | Type | Description |
|---|---|---|
getIsItemSelectedrequired | (item: T) => boolean | Returns whether the given item is currently selected. |
onSelectItemrequired | (event: {item: T; isSelected: boolean}) => void | Called when a row checkbox is toggled. isSelected is the new desired state. |
onSelectAllrequired | (event: {isAllSelected: boolean}) => void | Called when the select-all header checkbox is toggled. |
getIsAllSelectedrequired | () => boolean | Returns whether all selectable items are currently selected. |
getIsIndeterminate | () => boolean | Returns whether selection is partial (some but not all). Renders the select-all checkbox in indeterminate state. |
getIsItemSelectable | (item: T) => boolean (default: () => true) | Returns false for a row that can never be selected (no checkbox, an empty selection cell), unlike getIsItemEnabled, which shows a disabled checkbox. Use it for rows such as a read-only system row. This hook does not change select-all: your onSelectAll and getIsAllSelected must skip these rows. useTableSelectionState does this for you. |
getIsItemEnabled | (item: T) => boolean (default: () => true) | Returns false for a selectable row whose checkbox shows but is disabled and keeps its checked state, unlike getIsItemSelectable, which removes the checkbox. Use it for rows that are selectable in other conditions, such as a locked or busy row. This hook does not change select-all: your onSelectAll must not add or remove these rows. useTableSelectionState does this for you. |
getRowLabel | (item: T) => string | Derives a human-readable identity for a row; the row checkbox's hidden label becomes |
hasRowHighlight | boolean (default: true) | Paints checked rows with the accent wash. Set false when the surrounding UI already uses row background to mean something else (a row open in a detail panel, say). The wash is an inline style, so it cannot be overridden from userland. Only the background is dropped: aria-selected is still set on checked rows either way. |
Examples
Common configurations, variations, and states.Table with row selection checkboxes and a select-all header checkbox.
Controlled row selection with the reusable TableSelectionToolbar rendered in flow above the table. Product actions occupy the logical start; synchronized selection count and complete clear action occupy the logical end.
The reusable TableSelectionToolbar inside a capped, self-contained scroll region for a long non-sticky table below metric cards. The caller-owned sticky placement keeps actions 16px from the example scrollport without moving the table when selection changes.
Use with shadcn
Already using the shadcn registry workflow? Install the real Astryx package and a local public re-export. Component implementation source stays in Astryx.
This install URL expires with the draft preview.bashnpx shadcn@4.19.0 add https://astryx-64vrqe5a4-fbopensource.vercel.app/shadcn/hooks/use-table-selection.json