Switch
Native checkbox rendered as a switch while keeping native keyboard and form behavior.
Use the directive on native checkbox inputs and pair it with kui-field for field-level wiring.
import { KuiFieldComponent, KuiSwitchDirective } from '@kikita-labs/ui';Keep native label text next to the switch and reserve switch for binary settings.
<kui-field label="Notifications" hint="Control product and release notifications">
<label class="switch-option">
<input kuiSwitch type="checkbox" checked />
<span>Enable notifications</span>
</label>
</kui-field>Use the same size scale as other Kikita form controls.
<div class="switch-size-example">
<label class="switch-option">
<input kuiSwitch type="checkbox" size="xs" />
<span>Extra small</span>
</label>
<label class="switch-option">
<input kuiSwitch type="checkbox" size="sm" checked />
<span>Small</span>
</label>
<label class="switch-option">
<input kuiSwitch type="checkbox" size="md" checked />
<span>Medium</span>
</label>
<label class="switch-option">
<input kuiSwitch type="checkbox" size="lg" />
<span>Large</span>
</label>
</div>Inputs verified against @kikita-labs/ui v1.6.1 public typings.
| Name | Type | Default | Description |
|---|---|---|---|
| size | 'xs' | 'sm' | 'md' | 'lg' | — | Switch size mapped to Kikita switch tokens. |
| invalid | boolean | — | Marks the switch invalid outside a field error state. |
| id | string | undefined | — | Explicit id override. Inside kui-field, the field id is used when omitted. |
Switch adds role=switch while keeping the native checkbox element.
- Render
kuiSwitchon a nativeinput[type=checkbox]; the directive addsrole="switch"while the element keeps native checkbox semantics, keyboard support, and form participation. - Wrap the input in a native
labelso the switch text is the accessible name. - Space toggles the switch and Tab moves focus, matching native checkbox keyboard behavior; the directive does not add custom key handling.
- Use
kui-fieldfor group label, hint, error, andaria-describedbywiring instead of building described-by attributes by hand. - Set the native
disabledattribute to disable the control; use the directive'sinvalidinput to mark it invalid outside akui-fielderror state. - Use switch only for an immediate binary setting, not multi-choice selection.
- Per the Kikita UI library's state coverage notes, Switch has local playground coverage for off, on, hover, focus, invalid, disabled, sizes, and field wiring, but a dedicated assistive-technology review has not been completed yet.