Data input

Switch

A native checkbox styled as an on/off switch for a setting, with a label, help text and error state.

Class nameTypeDescription
toggleplf:toggleComponentA switch on a checkbox with role=switch
choiceplf:choicePartA row of a control and its label
choice-labelplf:choice-labelPartThe label, the click target

Default

A switch needs role="switch" and submits like a checkbox; use it for a setting that takes effect at once, and a Checkbox for a choice submitted with a form.

Space or clicking the label toggles the switch.

Invalid

Your application adds and removes aria-invalid and the message; start the message with “Error:” so the state does not rely on color alone.

Error: enable the setting to continue.

React

Switch from @pelatform/react renders this switch, a checkbox with role="switch", in a choice row with its label when it has children, and takes its description and error state from a Field or FieldGroup around it.

Prop Values Default
children The label, in a choice row with the switch None: the switch alone

The other props are the native checkbox’s, checked, defaultChecked, onChange, className and ref included.

CSS variables

Override on a root or on a single switch; --plf-choice-size does not apply to it.

Variable Default
--plf-switch-width 2.5rem (40px)
--plf-switch-height 1.5rem (24px); the thumb is 4px smaller than the inner height
--plf-choice-accent --plf-color-primary, the track of a switch that is on
--plf-control-height-md The label’s height on touch screens, at least 40px; 24px with a mouse

Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons