useTableSelection
@astryxdesign/core v0.7.1 · useTableSelection
The config is a MaybeRefOrGetter, so pass a getter or a ref to keep the plugin on the current values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
getIsItemSelected | (item: T) => boolean | — | Returns whether the given item is currently selected. |
onSelectItem | (event: { item: T; isSelected: boolean }) => void | — | Called when a row checkbox is toggled. isSelected is the new desired state. |
onSelectAll | (event: { isAllSelected: boolean }) => void | — | Called when the select-all header checkbox is toggled. |
getIsAllSelected | () => boolean | — | Returns whether all selectable items are currently selected. |
getIsIndeterminate | () => boolean | () => false | Returns whether selection is partial (some but not all). Renders the select-all checkbox in indeterminate state. |
getIsItemSelectable | (item: T) => boolean | () => true | Returns whether a row should show a checkbox. Non-selectable rows render nothing in the selection cell. |
getIsItemEnabled | (item: T) => boolean | () => true | Returns whether a row checkbox is interactive. Disabled rows keep their checkbox, rendered disabled, so the selection column stays aligned. |
getRowLabel | (item: T) => string | — | Derives a human-readable identity for a row; the row checkbox's hidden label becomes Select ${getRowLabel(item)} so screen readers announce which row each checkbox selects. Falls back to "Select row" when omitted. |
hasRowHighlight | boolean | 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). Only the background is dropped: aria-selected is still set on checked rows either way. |
Returns
| Field | Type | Description |
|---|---|---|
selection | TableSelectionContribution<T> | The plugin contribution the table reads. Put the whole plugin under any key of the plugins prop; the table picks up the one entry that has selection. |
selection.isAllSelected | () => boolean | Wraps getIsAllSelected. |
selection.isIndeterminate | () => boolean | Wraps getIsIndeterminate, or false when it is omitted. |
selection.isSelected | (row: T) => boolean | Wraps getIsItemSelected. |
selection.isSelectable | (row: T) => boolean | Wraps getIsItemSelectable, or true when it is omitted. |
selection.isEnabled | (row: T) => boolean | Wraps getIsItemEnabled, or true when it is omitted. |
selection.selectAll | (selected: boolean) => void | Calls onSelectAll with { isAllSelected: selected }. |
selection.selectRow | (row: T, selected: boolean) => void | Calls onSelectItem with { item: row, isSelected: selected }. |
selection.rowLabel | (row: T) => string | Wraps getRowLabel, or an empty string when it is omitted. |
selection.hasRowHighlight | boolean | undefined | The value from the config. Anything other than false keeps the wash. |