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

Skip to content

Switch

A control that indicates whether a setting is on or off.

Examples#

Labeling a switch#

An enclosing <label> is the simplest labeling pattern:

Rendering as a native button#

By default, SwitchRoot renders a <span> element to support enclosing labels. Prefer rendering the switch 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\SwitchRoot;
use function Phem\Ui\SwitchThumb;

SwitchRoot#

A control that turns a setting on and off: Base UI Switch.Root (switch is a reserved word in PHP), 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 of the app with phem:bind: the checkbox gets the bound value, also with nativeButton or uncheckedValue (a bound switch sends no uncheckedValue).

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

SwitchThumb#

The thumb that moves when the switch turns on.

PropTypeDefault
...restmixed—

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

Phem
Esc
↑↓ to navigate↵ to openEsc to close