Selection bar
The bulk actions for the rows checked in a selectable ds::table: the count,
the actions, Clear selection, and optionally "Select all N" across pages.
Covers the table's selectable too.
Anatomy
div[role=region][aria-label][x-data=dsSelectionBar][data-ds-selection=none|some]
├── span[data-ds-selection-count][data-ds-template][data-ds-all-template] "3 selected"
├── button[data-ds-selection-all][hidden] "Select all 240" total only
├── input[type=hidden][name=all][value=1][disabled][data-ds-selection-all-input]
├── button[data-ds-selection-clear][hidden] Clear selection (shown by the script)
├── div the actions (slot)
└── span[role=status].sr-only[data-ds-selection-status]
table[x-data=dsRowSelect][data-ds-row-select] ds::table selectable
├── th > span[data-ds-select-all-wrap][hidden] > ds::checkbox[data-ds-select-all] with columns
└── tr.has-checked:bg-accent-wash > td > ds::checkbox[data-ds-select-row][name=selected[]][value]
[@media(scripting:enabled)]:data-[ds-selection=none]:hidden: hidden at
none only where scripts run; with JavaScript off the actions always show and
post the checked rows. A row's box has a stable id hashed from the field and
the value, for Livewire's morph. The select-all cell is rendered in PHP and
echoed, so a table without selectable keeps its exact output
(TableUnchangedTest).
Behaviour
dsRowSelect: shows the select-all box; keeps it checked, mixed or clear; a
press on it sets every row; Shift with a press sets the run since the last
row pressed. Every box it changes gets a native change Event (never a
CustomEvent, whose detail x-model would take as the value).
dsSelectionBar: counts the checked [data-ds-select-row] inside for (else
its form), writes the count, sets data-ds-selection, says the count in its
status 400 ms after the last change, and on Clear unchecks every box (each
with a change) and focuses the select-all box. With total, when every row
on the page is checked and total is larger, it shows "Select all N";
pressed, it enables the hidden input, rewrites the count, dispatches
select-all ({ total }) and focuses Clear. Any later change takes it back.
Accessibility
| Role | region named by label (not toolbar: no arrow keys between its buttons) |
| Name | each row box by selectLabel; the select-all box by selectAllLabel, mixed when partly |
| Keyboard | Tab to each box and button; Space checks; Shift+Space does not range (pointer only) |
| Focus | Clear and Select all hide themselves, so they move focus to the select-all box and to Clear |
Do not
- Do not announce every change: the status is debounced.
- Do not combine with
tree: it throws. - Do not use
role="toolbar"without the arrow keys it promises.
From the package repo: edit this page on GitHub.