Skip to content

Switch

A switch button with role="switch".

Basic Usage

Basic usage

Disabled & Loading

disabled / loading

loading shows a loading animation and prevents toggling, for async submit scenarios.

Switch Labels

checked-text / unchecked-text render labels on the switch: at medium/large/xl sizes they appear inside the track on the side opposite the thumb; at size="xs" / size="small" the labels move outside the switch.

Switch labels

Sizes

size supports five tiers: xs / small / medium (default) / large / xl; invalid values fall back to medium with a warning.

Five sizes

Custom Color

color overrides the primary color of the checked state (defaults to --oas-color-primary).

Custom color

Events

Toggle events

Listen to oas-change (detail: { checked }):

API

Attributes

AttributeDescriptionTypeDefault
checkedWhether onboolean
checked-textLabel shown when on; inside the track at medium/large/xl, outside at xs/small
colorCustom primary color for the on state, overrides --oas-color-primary (CSS color value)
disabledDisabledboolean
loadingLoading state, prevents togglingboolean
sizeSize: xs / small / medium (default) / large / xl; invalid values fall back to medium with a warningstringmedium
unchecked-textLabel shown when off; inside the track at medium/large/xl, outside at xs/small

Events

EventDescription
oas-changeToggle, detail: { checked }