Switch

Material Design 3 switch web component (on/off toggle, optional thumb icons, form participation).

  • 2.7 KB gzipped
  • @lit-material/switch 0.0.4
  • Renders on the server

Example

Install

npm install @lit-material/switch @lit-material/tokens
import "@lit-material/switch";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-switch>

Material Design 3 switch.

Properties

PropertyAttributeTypeDefaultDescription
checkedcheckedbooleanfalse
disableddisabledbooleanfalse
errorerrorbooleanfalse
requiredrequiredbooleanfalse
namenamestring""
valuevaluestring"on"
formformstring | undefinednone
ariaLabelaria-labelstring | nullnullForwarded to the inner control; switches have no visible label so this is often required.
ariaLabelledByaria-labelledbystring | nullnull

Events

EventDescription
changeBubbles when the checked state changes via user interaction.

Slots

SlotDescription
iconAn optional icon shown in the thumb when unselected.
selected-iconAn optional icon shown in the thumb when selected.

CSS parts

PartDescription
switchThe container the track, thumb, state layer, and focus ring are rendered in.
trackThe pill-shaped track element.
thumbThe circular thumb element that slides within the track.
rippleThe state-layer element the hover/press feedback is drawn on.
focus-ringThe focus indicator element.

Source on GitHub npm