Skip to content
kitn AI/UI

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

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.

Starts on via the checked attribute.

Non-interactive and dimmed.

PropertyTypeDefaultNotes
theme'auto'Color mode (`auto` follows prefers-color-scheme).
checkedControlled checked state. Settable and reflected to the `checked` attribute. `el.checked = true` (or `<kai-switch checked>`) drives it; the toggle UI updates it and fires `kai-change`. Read `el.checked` for live state.
defaultCheckedInitial checked state on mount (uncontrolled seed). Bare attribute (`<kai-switch default-checked>`) turns it on.
disabledDisable interaction.
labelAccessible label.
nameForm-control name (paired with `value`).
valueSubmitted 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