Skip to content
Logic2BUI

Search docs

Search components and documentation

New
Menu

Switch

A control that allows the user to toggle between checked and not checked.

Installation

npx logic2b@next add switch

Usage

import { Switch } from "@/components/ui/switch"

<Switch id="airplane-mode" />

Usage notes

Built on Radix Switch.Root; forwards all of its props.

Examples

Controlled

Disabled

Settings list

Accessibility

  • Renders a switch role element that reflects its on/off state to assistive technology.
  • Toggle with Space or Enter when focused; fully reachable with Tab.
  • Associate a Label via htmlFor (or wrap the control) so the state has an accessible name.

Live playground

Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.

Generated JSX
<Switch
  defaultChecked
  aria-label="Enable notifications"
 />

API reference

Generated from the public TypeScript exports in src/ui/switch.tsx.

View JSON

Switch

Component
Props: React.ComponentProps<typeof SwitchPrimitive.Root>

Accessibility contract

Machine-readable behavior and consumer responsibilities for switch.

View JSON
Support
Primitive-managed
Pattern
switch
Radix Switch
Keyboard interactions for switch
KeysBehavior
Enter SpaceActivate the focused control.

Built-in semantics

  • Exposes role=switch and aria-checked.

Consumer responsibilities

  • Associate it with a label that describes the setting, not only the current state.