Krizaka UI
Krizaka UI
ComposantsFormulaires

Switch

An on/off setting that applies at once.

Web · ✓Mobile · ✓Bureau · ✓BêtaFormulaires
Niveau de support
Bêta
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";
Changez ses props : le composant se redessine, le code suit.
size
invalid
tsx
<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 tailwindcss

Styles

@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).

PropTypeDéfautDescription
childrenReactNode—The visible words, at the start of the row: they name the switch and the whole row toggles it.
descriptionReactNode—A line under the words, read with the switch as its hint.
invalidboolean—Marks it invalid: aria-invalid and data-invalid.
labelstring—The accessible name — required when no visible label names it, passed translated.
size"sm" | "md"mdsm · md.

Accessibilité

  • Radix Switch: role="switch" with aria-checked.
  • With children the row is a <label>: one control, named by the words, hinted by description (aria-describedby), never read twice.
  • label names it when no visible label does; otherwise use Field.Label htmlFor and aria-describedby for the hint.

Clavier

TouchesAction
SpaceToggles the switch.

Bonnes pratiques

  • Name the setting, not the state: “Autoplay”, not “Turn autoplay on”.
  • Give it children (and a description): 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.

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

Sur cette page