Switch
A switch turns one setting on or off at once, with no Save step. Teal means a rule is running; gold means a preference.
Preference and rule
Emails on
Show code
<KbSwitch checked={on} onChange={setOn} label="Email me when a request is handed off" />Emails on
Show code
<KbSwitch tone="teal" checked={on} onChange={setOn} label="Run this rule" />Disabled
Show code
<KbSwitch checked disabled onChange={noop} label="Managed by your plan" />When to use
- Use a switch for a setting that takes effect immediately.
- For a choice inside a form that is saved later, use a checkbox.
- Put the setting's name beside it in words and say the effect, not the state: Email me when a request is handed off.
- If turning it on has a cost or risk, ask first or use a button, not a switch.
Import
import { KbSwitch } from "@/components/ui/KbSwitch";
<KbSwitch checked={on} onChange={setOn} label="Email me when a request is handed off" />Props
| Prop | Type | Default | What it does |
|---|---|---|---|
checked | boolean | None | Whether it is on. |
onChange | (next: boolean) => void | None | Called with the new state. |
label | string | None | The accessible name. Required unless labelledBy is set. |
labelledBy | string | None | The id of the row title that names the switch. |
tone | "gold" | "teal" | "gold" | Teal for a rule, gold for a preference. |
disabled | boolean | None | Fades it and removes it from the tab order. |
Keyboard and screen readers
- Renders a button with role switch and aria-checked. Space and Enter toggle it.
- A switch has no visible text of its own, so it must be named with label or labelledBy.
- The target is 44 by 24px, and 44px tall under 860px wide.
- On and off differ by position and fill, not by colour alone.