Switch

A toggle switch for binary on/off states.

Primitive: SwitchARIA: role="switch"Keyboard: Space, Enter
Notifications enabled
Dark mode
Disabled
switch_example.rs
use stratum_leptos::*;

view! {
    <Switch default_checked=true>"Notifications"</Switch>
    <Switch>"Dark mode"</Switch>
    <Switch disabled=true>"Disabled"</Switch>
}

Installation

stratum add switch

Props

PropTypeDefaultDescription
checkedOption<bool>NoneControlled checked state
default_checkedboolfalseInitial state for uncontrolled usage
disabledboolfalsePrevents interaction
on_changeOption<Callback<bool>>NoneFires when toggled

Accessibility

  • Renders with role="switch" and aria-checked.
  • Space and Enter toggle the switch.
  • Focus visible indicator always shown.

Source

Primitive: switch.rs
Styled: switch.rs