Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

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…

Read the release notes

data-select-all

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-all attribute 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.

Usage

  1. Put data-select-all on an <input type="checkbox">. Its value is a CSS selector for the target checkboxes.
  2. 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.
  3. 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.
  4. Toggling the master changes each enabled target that needs it and fires a real change event on each one.
  5. 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.

Options

Attribute On Description
data-select-all master checkbox 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.

Events

Event Detail When
select-all:change { checked: number, total: number, selected: HTMLInputElement[] } 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.

Styling

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.

Checkbox list

A master in a <legend> controls the options in its <fieldset>. The second half of the overview demo shows it.

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.

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-select-all or <data-table>?

  • data-select-all — any checkbox group: settings lists, plain tables, filters. You keep your own markup.
  • <data-table> — when the table also needs sorting, filtering, pagination or a bulk-action bar.
↑