Switch
An on/off setting that applies at once.
- Domaine
- Formulaires
- Niveau de support
- Taille
- 1.2 kB gzip, budget 6.0 kB
- Qui l'utilise
- 18 fichiers des produits et sites en production l'importent (Verikora : 4, Folioviv : 2, Sovkora : 8, krizaka.com : 1) Compté dans l'inventaire daté du 2026-11-23.
import { Switch } from "@krizaka/ui/switch";<Switch defaultChecked label="Notifications" />Web et mobile — le même composant pour React et React Native. Bêta : son API peut encore changer à une version mineure.
Pourquoi il est là. Used by Sovkora, Verikora, Folioviv, krizaka.com.
Quand l’utiliser
- For a setting that takes effect immediately: autoplay, notifications, a weekly digest.
Quand ne pas l’utiliser
- For a choice submitted with a form, or an agreement.À la place : Checkbox
- For more than two states.À la place : Radio group
- To run an action.À la place : Button
Installation
Installer
npm install @krizaka/ui @krizaka/tailwind @krizaka/tokens tailwindcssStyles
@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";Importer
import { Switch } from "@krizaka/ui/switch";Exemples
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 | Défaut | 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. |
Accessibilité
- 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.
Clavier
| Touches | Action |
|---|---|
| Space | Toggles the switch. |
Bonnes pratiques
- 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.
Composants liés
Générée depuis le code de @krizaka/ui 5.3.4 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub