SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

tableSelection

Why JS: HTML has no select-all checkbox, no indeterminate state outside script and no shift-click range.

tsx
import { tableSelection } from "@sdxc/ui/app";

Usage

Keeps a table's selection checkboxes consistent: select-all checks or clears every enabled row, mirrors the rows as checked, indeterminate or clear, and a shift-click checks or clears every row between the last clicked one and this one. Each row it changes fires a bubbling change, as a click would, so a selection bar counting [data-selection-item]:checked hears every change; each row's <tr> carries aria-selected while checked. The host is the region it governs: a <table>, a wrapper, or a marker inside a table, which hands the work to its closest <table>.

Signature

typescript
tableSelection(): MixinDescriptor<HTMLElement>

Examples

tsx
<Table mix={[tableSelection()]}>…</Table>
tsx
<span hidden mix={[tableSelection()]} />

The events, constants and types its module publishes, each imported from @sdxc/ui/app too.

Constant

SELECTION_ITEM_SELECTOR

Selector for a per-row checkbox, the contract any selectable list renders.

typescript
const SELECTION_ITEM_SELECTOR = "input[type=checkbox][data-selection-item]"
Constant

SELECTION_ALL_SELECTOR

Selector for the checkbox that selects or clears every row at once.

typescript
const SELECTION_ALL_SELECTOR = "input[type=checkbox][data-selection-all]"
Function

keepSelection

Keeps scope's row boxes true to the selection when a frame reload or navigation patches them against server HTML, until signal aborts. The patch matches rows by position and keeps each box's live check, so afterwards a box is checked exactly when it holds a record that was checked before; once a form submitted checked rows, its boxes take what the server rendered instead. restored runs after every such patch, even one that changed no box.

typescript
keepSelection(scope: HTMLElement, signal: AbortSignal, restored: () => void): void
ParameterTypeRequiredDescription
scopeHTMLElementYesThe region holding the row boxes.
signalAbortSignalYesEnds the watch once the binding leaves the document.
restored() => voidYesRe-derives what the binding draws from the boxes.
@sdxc/ui

Can’t find it? Contact us