0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Master checkbox for bulk selection. Add data-select-all to a checkbox to control a group of related checkboxes, with indeterminate state, disabled items skipped and a live count.
Overview
The data-select-allattribute makes a checkbox the master toggle for a group of target checkboxes. Toggling the master checks or unchecks every enabled target. When targets change one by one, the master shows the result: checked when all are selected, indeterminate ("mixed") when some are, unchecked when none are.
Table with select all
123456789101112131415161718
<table><thead><tr><thscope="col"><inputtype="checkbox"data-select-all=".row-select"aria-label="Select all"></th><thscope="col">Name</th></tr></thead><tbody><tr><td><inputtype="checkbox"class="row-select"aria-label="Select Alice Johnson"></td><td>Alice Johnson</td></tr><tr><td><inputtype="checkbox"class="row-select"aria-label="Select Bob Smith"></td><td>Bob Smith</td></tr></tbody></table>
Usage
Put data-select-all on an <input type="checkbox">. Its value is a CSS selector for the target checkboxes.
Targets are searched for in the nearest ancestor that is [data-select-all-scope], <table>, <form> or <fieldset>. Without such an ancestor, the whole document is searched.
Disabled targets (disabled, or inside a disabled <fieldset>) are never toggled and do not count toward the total. The master can still reach "all" while a locked item stays unchecked.
Toggling the master changes each enabled target that needs it and fires a real change event on each one.
The master re-syncs when a target changes, after a form reset, when targets are added, removed, disabled or hidden inside the scope, and when data-select-all itself changes.
State is kept in script, not in a marker attribute, so a cloned master (for example in a duplicated fieldset) works on its own. When the master leaves the document, its listeners and observer are removed.
CSS selector for the target checkboxes (e.g. .row-select), searched inside the scope.
data-select-all-scope
ancestor
Limits the search for targets and for the count element. Use it when the same target selector appears in several groups, or when the master sits outside the table or fieldset it controls.
data-selected-count
any element in the scope
Shows how many targets are checked, formatted for the element's language (Intl.NumberFormat with the nearest lang). On an <output> its value is set.
Fired from the master (bubbles) whenever the set of checked targets changes, whether through the master, a single target, a reset or added rows. total counts enabled targets only.
There are no utility-specific styles. The master is a native checkbox, so :checked and :indeterminate style it, and VB's checkbox styles already cover the mixed state.
Accessibility
The master uses the native indeterminate property, which screen readers announce as "mixed".
Give the master a name. Without a visible label (for example in a table header), use aria-label="Select all". Give each row checkbox a name that says which row it selects ("Select Alice Johnson"), not just "Select row".
Use an <output data-selected-count> for the count. <output> has an implicit status role, so changes are announced politely. A plain <span> or <strong> is updated silently.
Targets get real change events, so validation and other listeners run.
Disabled targets stay as they are. Explain why an item is locked in its label.
Without JavaScript, every checkbox still works on its own.
Examples
Count display and form reset
The required option is checked and disabled, so the master ignores it. Reset puts the defaults back and the master and count follow.
Count with an output
123456789101112
<form><fieldset><legend>Notifications</legend><label><inputtype="checkbox"data-select-all='[name="notify"]'> All notifications</label><label><inputtype="checkbox"name="notify"value="mentions"> Mentions</label><label><inputtype="checkbox"name="notify"value="replies"> Replies</label><label><inputtype="checkbox"name="notify"value="follows"> New followers</label><label><inputtype="checkbox"name="notify"value="billing"checkeddisabled> Billing (required)</label><p><outputdata-selected-count>0</output> of 3 optional notifications on</p></fieldset><buttontype="reset">Reset</button></form>
Checkbox list
A master in a <legend> controls the options in its <fieldset>. The second half of the overview demo shows it.
Checkbox list
12345678
<fieldset><legend><label><inputtype="checkbox"data-select-all=".option-check"> Select all options</label></legend><label><inputtype="checkbox"class="option-check"> Option A</label><label><inputtype="checkbox"class="option-check"> Option B</label><label><inputtype="checkbox"class="option-check"> Option C</label></fieldset>
Scoping
Two groups use the same .pick selector. Each master controls only the checkboxes in its own fieldset, and each count shows only its own group.
Two scoped groups
1234567891011121314
<fieldset><legend>Fruit</legend><label><inputtype="checkbox"data-select-all=".pick"> All fruit</label><label><inputtype="checkbox"class="pick"> Apple</label><label><inputtype="checkbox"class="pick"> Pear</label><p>Selected: <outputdata-selected-count>0</output></p></fieldset><fieldset><legend>Vegetables</legend><label><inputtype="checkbox"data-select-all=".pick"> All vegetables</label><label><inputtype="checkbox"class="pick"> Carrot</label><p>Selected: <outputdata-selected-count>0</output></p></fieldset>
When the master is outside the element that holds the targets, wrap both in data-select-all-scope. The nearest scope wins, so a master inside a table that sits inside a [data-select-all-scope] section controls only that table.
Related
<data-table> — row selection with bulk actions, built in.
<form-field> — labels, hints and errors for form controls.