Skip to content

Switch

Boolean on/off toggle. Since it renders a plain <input type="checkbox" role="switch"> with no associated <label>, always set label (used as aria-label).

Renders in light DOM (scoped styles, not Shadow DOM) on purpose: the checkbox this component renders is a real descendant of whatever <form> wraps it, so FormData, native required validation, and <fieldset disabled> all work without any extra wiring — the visible track/thumb are styled purely off the checkbox’s own :checked/:disabled state via Tailwind peer-* variants, and wrapping everything in a <label> gives click-to-toggle for free. form.reset() restores the original default, the same as Input and Select.

<and-switch label="Enable notifications" name="notifications" checked></and-switch>

Properties

PropertyAttributeDescriptionTypeDefault
checkedcheckedWhether the switch is on.booleanfalse
customClassclassAdditional CSS classes from the consumer.string''
describedBydescribed-byID of the element that describes this switch (e.g. hint or error message).string''
disableddisabledDisables interaction when true.booleanfalse
labellabelAccessible label for the switch (used when no visible label exists).string''
namenameName attribute forwarded to the native checkbox — required for it to show up in FormData.string''
requiredrequiredMarks the switch as required (must be checked to submit).booleanfalse
valuevalueValue submitted in FormData when checked. Defaults to the native checkbox default ("on") when unset.string''

Events

EventDescriptionType
andSwitchChangeEmitted when the checked state changes.CustomEvent<boolean>
Generated from packages/web-components/src/components/and-switch/readme.md — keep this in sync with the Stencil source, don't hand-edit the numbers.