Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Forms

Toggle

An on/off switch for a setting that takes effect immediately.

Selector: mui-toggle

Import
import { Toggle } from '@mushilu-san/ui/forms';
PreviewCode

Loading example…

Overview

Toggle has role="switch" and aria-checked. Its checked model is two-way bindable. Set label so the switch has an accessible name.

Use a toggle when the change applies right away. For a choice that is submitted with a form, use a checkbox.

When to use

  • Turning a feature or notification on or off.
  • A setting where the change is saved or visible immediately.

When not to use

  • A choice that is submitted with a form. Use a checkbox. Use Checkbox instead.

Examples

Sizes and disabled

PreviewCode

Loading example…

Guidelines

Do

  • Use a label that describes the setting, not the state. "Email alerts", not "On".

Don't

  • Do not use a toggle for an action, such as "Send". Use a button.

Accessibility

Roles and attributes

ElementRoleNotes
hostswitcharia-checked follows checked. aria-disabled when disabled.

Keyboard

KeysAction
TabShiftTabMoves focus to and from the switch.
SpaceEnterToggles the switch.
  • Set label on the switch, or give it an aria-label.

API

Toggle

Selector: mui-toggle

NameTypeDefaultDescription
size'sm' | 'md' | 'lg''md' Switch size: `sm`, `md` or `lg`. Default `md`.
labelstring | undefined— Accessible name for the switch, also shown as text when provided.
disabledbooleanfalse Disables the switch. Sets `aria-disabled` and ignores input. Accepts attribute presence, e.g. <… disabled>.
NameTypeDefaultDescription
checkedbooleanfalse Whether the switch is on. Two-way bindable with `[(checked)]`.

CSS parts

  • ::part(root)

Tokens

  • --mui-color-primary
  • --mui-color-border
  • --mui-color-surface
  • --mui-color-focus-ring
  • --mui-touch-target