Switch
An on/off setting that applies at once.
- Domain
- Forms
- Support level
- Size
- 1.2 kB gzip, budget 6.0 kB
- Who uses it
- 18 files of the live products and sites import it (Verikora: 4, Folioviv: 2, Sovkora: 8, krizaka.com: 1) Counted in the dated inventory of 2026-11-23.
import { Switch } from "@krizaka/ui/switch";<Switch defaultChecked label="Notifications" />Web and mobile — the same component for React and React Native. Beta: its API may still change in a minor version.
Why it is here. Used by Sovkora, Verikora, Folioviv, krizaka.com.
When to use
- For a setting that takes effect immediately: autoplay, notifications, a weekly digest.
When not to use
- For a choice submitted with a form, or an agreement.Use instead: Checkbox
- For more than two states.Use instead: Radio group
- To run an action.Use instead: Button
Installation
Install
npm install @krizaka/ui @krizaka/tailwind @krizaka/tokens tailwindcssStyles
@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";Import
import { Switch } from "@krizaka/ui/switch";Examples
Off
Named by label.
On
defaultChecked (or checked + onCheckedChange).
Disabled
Off and on.
Small
size="sm".
With a visible label
A Field.Label and a hint on the same line.
Settings row
children and description: text at the start, switch at the end, the whole row clickable (44 px).
Props
An on/off switch: checked/defaultChecked + onCheckedChange. With children (and a description) it draws its
own settings row: the words at the start, the switch at the end (mirrored under dir="rtl"), the whole row
clickable, 44 px high or more. It stays one control with one name (children) and one hint (description).
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The visible words, at the start of the row: they name the switch and the whole row toggles it. |
description | ReactNode | — | A line under the words, read with the switch as its hint. |
invalid | boolean | — | Marks it invalid: aria-invalid and data-invalid. |
label | string | — | The accessible name — required when no visible label names it, passed translated. |
size | "sm" | "md" | md | sm · md. |
Accessibility
- Radix Switch:
role="switch"witharia-checked. - With
childrenthe row is a<label>: one control, named by the words, hinted bydescription(aria-describedby), never read twice. labelnames it when no visible label does; otherwise useField.Label htmlForandaria-describedbyfor the hint.
Keyboard
| Keys | Action |
|---|---|
| Space | Toggles the switch. |
Best practices
- Name the setting, not the state: “Autoplay”, not “Turn autoplay on”.
- Give it
children(and adescription): the words at the start, the switch at the end, the whole row clickable. There is no alignment prop — start and end follow the reading direction.
Related components
Generated from the code of @krizaka/ui 5.3.4: its meta.ts, its examples and its types.Edit this documentation on GitHub