Skip to Content
Urban Cowboy
Components

Switch

Radix-backed accessible switch with a shared Label pairing pattern.

Switch is the shared binary control for admin settings and feature toggles. The example uses a docs-only controlled harness so it works without BookingProvider, D1 or Worker access.

*
string
*
boolean
*
boolean

Props and states

PropValuesNotes
checkedbooleanControlled state from the caller
defaultCheckedbooleanRadix's uncontrolled initial state; use when the caller does not own state
onCheckedChange(checked: boolean) => voidNeeded when handling controlled state changes
disabledbooleanRemoves pointer affordance and lowers opacity
idstringPair with Label htmlFor for an accessible name

Use either checked + onCheckedChange (controlled) or defaultChecked (uncontrolled) — not both. onCheckedChange is optional for uncontrolled usage.

States covered: unchecked, checked, disabled and the paired-label presentation. The component keeps Radix's keyboard and screen-reader semantics; do not replace the thumb with a custom span.

Responsive behaviour

The control is 36px wide and does not grow with its label. Labels wrap beside it on narrow screens rather than forcing horizontal scrolling.

Usage

import { Switch } from '@/components/ui/switch';
import { Label } from '@/components/ui/label';

<Switch id="dog" checked={dogFriendly} onCheckedChange={setDogFriendly} />
<Label htmlFor="dog">Dog Friendly Room</Label>

View source