Skip to content
kitn AI/UI

Switch

kai-switch

Manages its own state and reports the change once, so a settings row needs no wiring.

  • Shadow DOM
  • 1 event
  • role="switch"
  • Keyboard operable
  • Self-managing

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/web-components';
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.

Starts on via the checked attribute.

Non-interactive and dimmed.

PropertyTypeDefaultNotes
theme'auto'Color mode (`auto` follows prefers-color-scheme).
checked—Controlled checked state, reflected to the `checked` attribute. The toggle updates it and fires `kai-change`.
defaultChecked—Initial checked state on mount (uncontrolled seed). Bare attribute (`<kai-switch default-checked>`) turns it on.
disabled—Disable interaction.
label—Accessible label.
name—Form-control name (paired with `value`).
value—Submitted value when checked (paired with `name`). Defaults to `'on'`.
EventDetailNotes
The toggle changed.
MethodSignatureNotes
(): voidFlip the switch and fire `kai-change` (no-op while disabled).
(options?: FocusOptions): voidFocus the inner `role="switch"` button (the host element can't reach it).

This element wraps these SolidJS components — reach for them directly when you need finer control than the props expose.

Switch