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

Skip to content

Checkbox

An easily stylable checkbox component.

Examples#

Labeling a checkbox#

An enclosing <label> is the simplest labeling pattern:

Rendering as a native button#

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

Form integration#

Use Field to handle label associations and form integration:

API reference#

Import the components of the family:

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

Checkbox#

A box that the user checks and unchecks: Base UI Checkbox.Root, on the phem-toggle controller.

Put it in a <label> with its text. A hidden checkbox keeps the state for a form (name, value). Bind it to a bool state with phem:bind. With nativeButton, it is a <button> for a sibling <label for> (give it an id), and a hidden input keeps the state (a hidden checkbox when it is bound). In a CheckboxGroup, the group owns the state: give the checkbox a value, and parent to the checkbox that checks all the items.

PropTypeDefault
defaultCheckedboolfalse
indeterminateboolfalse
disabledboolfalse
readOnlyboolfalse
requiredboolfalse
parentboolfalse
nativeButtonboolfalse
name?stringnull
value?stringnull
checked?Boundnull
children?Htmlnull
...attrsarray[]

CheckboxIndicator#

The check mark. It shows only when the checkbox is checked, or a dash when it is indeterminate.

PropTypeDefault
children?Htmlnull
...restmixed—

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/Checkbox.phem.

Phem
Esc
↑↓ to navigate↵ to openEsc to close