Skip to main content

Switch

<sc-switch></sc-switch>

This component let users create switch.

Toggle Me

Disabled

Use the disabled property to disable the switch

Disabled

Custom Size

Use the css variable design tokens to change the sizes of the switch for an instance.

Component Codex

Properties

PropertyDescriptionTypeDefault
checkedDraws the switch in a checked state.booleanfalse
disabledDisables the switch.booleanfalse
editThis will be true as a workaround in the block editor to focus on the content.booleanfalse
invalidThis will be true when the control is in an invalid state. Validity is determined by the `required` prop.booleanfalse
nameThe switch's name attribute.string
requiredMakes the switch a required field.booleanfalse
reversedboolean
valueThe switch's value attribute.string

Events

EventDescriptionType
scBlurEmitted when the control loses focus.CustomEvent<void>
scChangeEmitted when the control's checked state changes.CustomEvent<void>
scFocusEmitted when the control gains focus.CustomEvent<void>

Methods

reportValidity() => Promise<boolean>

Checks for validity and shows the browser's validation message if the control is invalid.

Shadow Parts

PartDescription
base
control
description
thumb
title