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 { KuiField, KuiSwitch } 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>Set defaults.switch once for the application or for a subtree. Each option resolves as local input > defaults.switch.<option> > built-in default.
import { provideKikitaUi } from '@kikita-labs/ui';
export const appConfig: ApplicationConfig = {
providers: [
provideKikitaUi({
defaults: {
switch: {
/* options below */
},
},
}),
],
};| Name | Type | Default | Description |
|---|---|---|---|
| size | 'xs' | 'sm' | 'md' | 'lg' | — | Component size. Takes precedence over the global defaults.size. |
Inputs verified against @kikita-labs/ui v2.0.0 public typings.
| Name | Type | Default | Description |
|---|---|---|---|
| size | 'xs' | 'sm' | 'md' | 'lg' | undefined | undefined | Switch size mapped to Kikita switch tokens. Resolved from defaults.switch.size, then the parent field, then the global defaults.size, then md. |
| invalid | boolean | false | Marks the switch invalid outside a kui-field error state. With [formField] the Field state wins. |
| id | string | undefined | undefined | Explicit id override. Inside kui-field, the field id is used when omitted. |
| KuiSwitchOptions | interface | - | Shape of defaults.switch: size. |
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. - A required
kui-fieldexposesaria-requiredon the switch, and the checked switch stays visible underforced-colors: active. - 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.
Consumer-visible changes of @kikita-labs/ui 2.0 for Switch.
- The directive class is
KuiSwitch; theDirectivesuffix is gone. - The default size moved to
provideKuiDefaults({ switch: { size } }); the input is nowundefineduntil set. - A required
kui-fieldsetsaria-requiredon the switch. - The checked and indeterminate states are covered by forced-colors, and disabled switches use the shared
--kui-opacity-disabled.