This documentation is under construction. Pages can be missing or change at any time. Follow it on GitHub.

Skip to content

Checkbox Group

Provides shared state to a series of checkboxes.

Examples#

Labeling a checkbox group#

Label the group with aria-labelledby and a sibling label element. An enclosing <label> is the simplest labeling pattern for each checkbox.

Rendering as a native button#

By default, Checkbox renders a <span> element to support enclosing labels. Prefer rendering each checkbox as a native button with nativeButton when using sibling labels (for/id).

Form integration#

Use Field and Fieldset for group labeling and form integration.

Parent checkbox#

A checkbox that controls other checkboxes within a CheckboxGroup can be created:

- Pass an array of all the child checkbox values to the allValues prop on the CheckboxGroup component

- Add the parent boolean prop to the parent Checkbox

The group controls the parent checkbox’s indeterminate state when some, but not all, child checkboxes are checked.

Nested parent checkbox#

A CheckboxGroup with a value inside another group is an item of that group: the outer parent checks all its checkboxes, and is indeterminate when some of them are checked.

API reference#

Import the components of the family:

use Phem\Ui\Checkbox;
use Phem\Ui\CheckboxGroup;
use function Phem\Ui\CheckboxIndicator;

CheckboxGroup#

A group of checkboxes with one state: Base UI CheckboxGroup, on the phem-checkbox-group controller. defaultValue lists the values of the checked checkboxes, and allValues the values that a parent checkbox checks. Label it with aria-labelledby. With disabled, all its checkboxes are disabled. With a value, a group in a group is an item of the outer group: the outer parent checks all its checkboxes.

PropTypeDefault
defaultValuearray[]
allValuesarray[]
value?stringnull
disabledboolfalse
children?Htmlnull
...attrsarray[]

The source of the examples: examples/ui/CheckboxGroup.phem.

Phem
Esc
↑↓ to navigate↵ to openEsc to close