Krizaka UI
Krizaka UI
ComponentsForms

Switch

An on/off setting that applies at once.

Web · ✓Mobile · ✓Desktop · ✓BetaForms
Domain
Forms
Support level
Beta
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";
Change its props: the component re-renders, the code follows.
size
invalid
tsx
<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 tailwindcss

Styles

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

PropTypeDefaultDescription
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.

Accessibility

  • 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.

Keyboard

KeysAction
SpaceToggles the switch.

Best practices

  • 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.

Generated from the code of @krizaka/ui 5.3.4: its meta.ts, its examples and its types.Edit this documentation on GitHub

On this page