Switch
kai-switch
A toggle switch for a setting that applies the moment it flips — “Temporary chat”, notifications, a feature flag. It manages its own on/off state and reports changes with a single event.
- Shadow DOM
- 1 event
- role="switch"
- Keyboard operable
- Self-managing
Preview
Section titled “Preview”Set the initial state with the checked attribute and read changes from kai-change:
<kai-switch checked label="Temporary chat"></kai-switch>
<script type="module"> import '@kitn.ai/ui/elements';
document.querySelector('kai-switch') .addEventListener('kai-change', (e) => console.log('checked:', e.detail.checked));</script>- Self-managing — the switch toggles on click or Space/Enter and tracks its own state; you only listen for
kai-change. checked— a bare attribute (<kai-switch checked>) starts it on.label— sets the accessible name (aria-label); the switch is visual-only, so always provide one.disabled— blocks interaction and dims the control.
Examples
Section titled “Examples”Starts on via the checked attribute.
Disabled
Section titled “Disabled”Non-interactive and dimmed.
| Property | Type | Default | Notes |
|---|---|---|---|
| checked | boolean | — | Initial checked state. Bare attribute (`<kai-switch checked>`) turns it on. |
| disabled | boolean | — | Disable interaction. |
| label | string | — | Accessible label. |
Events
Section titled “Events”| Event | Detail | Notes |
|---|---|---|
| kai-change | | The toggle changed. |
Composed from
Section titled “Composed from”This element wraps these SolidJS components — reach for them directly when you need finer control than the props expose.
Switch