videorc/ui

Switch

The one control for a boolean, on Base UI. On, its track is the chrome fill and its knob the inverse chrome bead.

YouTube asks every stream to say whether it's made for kids.

Installation

$ pnpm dlx shadcn@latest add @videorc/switch

Usage

import { Switch } from "@/components/ui/switch";
<Field orientation="horizontal">
  <FieldLabel>Save local recording</FieldLabel>
  <Switch />
</Field>

A switch is the one way to turn something on or off: never an On and Off pair, and never a toggle button. In a settings list, put it in a SettingsRow.

Examples

Sizes

sm is a 16 px track for a row that is denser than a page, such as a source's quick control. It is a track size, not a control height.

Disabled

A disabled switch says why in its description. Disable every control a lock covers, rather than leaving one that looks enabled.

Locked while you're recording or live.

Theming

Token or attributeMeaning
chrome-fillThe track while on
bg-input/90The recessed track while off
chrome-beadThe knob while off
chrome-bead-inkThe knob on its chrome track: black in dark, pearl in light
ring-knob-ringThe knob's hairline rim
data-checked, data-unchecked, data-disabledThe state, from Base UI
data-sizedefault (32 × 20) or sm (24 × 16)

Keyboard

KeyAction
SpaceToggles the switch
EnterToggles the switch
TabMoves focus to the next control

Accessibility

The switch is a role="switch" span with aria-checked, beside a hidden native input that carries its form value. Its id goes on that hidden input, so a FieldLabel toggles it on click and Base UI names the switch by that label. Never put a switch inside a button or a clickable row: a control inside a control can't be reached on its own.

API reference

Every Base UI Switch root prop, plus:

Prop

Type