Drivn vs shadcn/ui — Switch Compared
Drivn ships a ~40 line zero-runtime Switch built on a native button; shadcn/ui wraps @radix-ui/react-switch. Here is the practical difference.
Choosing between the Drivn and shadcn/ui Switch comes down to one question: should the toggle be a button you can read top to bottom, or a wrapper around a Radix primitive? Both draw the same thing on screen, a rounded track with a sliding thumb, and both expect the checked value to live in your own component. What differs is everything underneath.
The Drivn Switch is one client file of about forty lines, and the track is the element itself: a native <button type="button" role="switch"> with aria-checked={checked}, filled bg-primary when on and bg-border when off. A bg-primary-foreground thumb slides from translate-x-[3px] to translate-x-[25px], and a focus-visible:ring-[3px] ring marks keyboard focus. The file imports React and cn() and nothing else, so there is no Radix package or class-variance-authority to audit, upgrade, or tree-shake.
shadcn/ui wraps @radix-ui/react-switch. That adds defaultChecked for uncontrolled use, data-state attributes to style against, and a hidden checkbox input that joins native form submissions when the switch sits inside a <form>. Those features are real, and so is the extra package in your lockfile.
The sections below walk through the source, the checked + onChange contract, how each version is labelled and announced, and how to decide which one belongs in your project. The Drivn CLI installs the file in one command.
Side-by-side comparison
| Feature | Drivn | shadcn/ui |
|---|---|---|
| Install command | npx drivn add switch | npx shadcn@latest add switch |
| Underlying implementation | Native button with role="switch" | @radix-ui/react-switch primitives |
| Runtime UI dependencies | cn() utility only — zero npm UI packages | @radix-ui/react-switch + peers |
| Component lines | ~40 lines, single file | Short wrapper file + the @radix-ui/react-switch package |
| Public API shape | <Switch checked onChange /> | <Switch checked onCheckedChange /> |
| Controlled state | checked + onChange in caller | checked + onCheckedChange in caller |
| Uncontrolled state | Not built-in — caller owns useState | defaultChecked supported via Radix |
| ARIA pattern | role="switch" + aria-checked on button | Full WAI-ARIA Switch pattern via Radix |
| Keyboard behaviour | Browser default — Space/Enter on button | Space/Enter on the Radix Root button |
| Focus ring | focus-visible:ring-[3px] ring-ring/50 | focus-visible ring classes in the wrapper |
| Form integration | Pair with hidden input in caller | Hidden checkbox input rendered inside a <form> |
| Thumb animation | CSS translate-x 200ms | CSS translate-x 200ms via data-state |
| Disabled state | Standard button disabled attribute | Radix data-disabled + standard attribute |
| Client component | Yes — 'use client' | Yes — 'use client' |
| License | MIT | MIT |
Controlled state shape — checked + onChange
Both libraries expect controlled state from the caller. Drivn names the callback onChange and types it as (checked: boolean) => void — note the Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onChange'> on the props type so the native button onChange does not collide. shadcn/ui (via Radix) names the callback onCheckedChange, which is the Radix convention to disambiguate from native form onChange events. Same idea, different name.
Drivn does not ship an uncontrolled mode — there is no defaultChecked prop, no internal useState. If you want uncontrolled state you wrap the Switch in your own component and own the state there. Radix-backed shadcn/ui supports both controlled (checked + onCheckedChange) and uncontrolled (defaultChecked) out of the box because Radix maintains the internal state machine for you. For most forms this difference is invisible — the value already lives in form state next to your Input and Textarea fields, so the Switch is controlled at the form level anyway. For one-off toggles, uncontrolled mode is a small ergonomic win.
1 "use client" 2 3 import * as React from "react" 4 import { Switch } from "@/components/ui/switch" 5 6 export default function NotificationToggle() { 7 const [enabled, setEnabled] = React.useState(false) 8 9 return ( 10 <Switch 11 checked={enabled} 12 onChange={setEnabled} 13 /> 14 ) 15 }
When the shadcn + Radix path still wins
Three situations push you toward the Radix-backed shadcn Switch even though Drivn ships fewer dependencies. The first is a project already wired through @radix-ui/react-form or another Radix form layer — the Switch primitive integrates with that form context cleanly, broadcasts its state via data-state, and participates in the form submission lifecycle without extra glue. Pairing the Drivn Switch with the same form layer means adding a hidden <input type="checkbox"> next to the button and syncing it manually.
The second is a design system mandate of WAI-ARIA exhaustiveness — every component audited against the full pattern, every keystroke documented, every screen reader output specified. Radix is engineered for that bar; the Drivn Switch is engineered to cover the practical 95% with a third of the surface area. The third is an existing shadcn project — switching one component to Drivn means running two registries side by side, two CLIs in the build, and two @/components/ui conventions. Stay on shadcn unless you are migrating the whole surface. For a fresh start where bundle size, registry simplicity, and dot-notation parity with the rest of the Drivn library matter more than Radix-grade accessibility, the Drivn Switch is the cleaner pick.
1 # Drivn — one CLI, one registry 2 npx drivn add switch 3 4 # shadcn/ui — wraps a Radix package 5 npx shadcn@latest add switch 6 # also installs @radix-ui/react-switch
Install Drivn in one command
Copy the source into your project and own every line. Zero runtime dependencies, pure React + Tailwind.
npx drivn@latest createRequires Node 18+. Works with npm, pnpm, and yarn.
Frequently asked questions
No. The Drivn Switch is a single file at packages/drivn/src/registry/components/switch.ts that imports React and the local cn() utility from @/utils/cn — nothing else. There is no @radix-ui/react-switch dependency, no class-variance-authority, no headless toggle library. The component is a native HTML button with role="switch" and aria-checked, plus a thumb span that translates via CSS. The whole file is roughly forty lines and ships as TypeScript source via the Drivn CLI.
Drivn calls it onChange and types it as (checked: boolean) => void. To prevent a collision with the native button onChange event, the SwitchProps interface uses Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onChange"> before adding the custom signature. shadcn/ui follows the Radix convention and uses onCheckedChange to disambiguate from form onChange events. When moving a shadcn codebase onto Drivn, rename each onCheckedChange to onChange and the rest of the call site stays the same.
No. The Drivn Switch is controlled-only — the caller owns the boolean state via useState (or a form library) and passes it down through the checked prop. There is no defaultChecked, no internal state machine, no useUncontrolledState hook. If you need uncontrolled behaviour, wrap the Switch in a small component that owns the state and exposes its own API. The shadcn/ui Switch inherits Radix uncontrolled mode via defaultChecked out of the box.
The thumb is an absolutely positioned span sized w-5 h-5 with bg-primary-foreground, rounded-full, and shadow-md. Its base class adds transition-transform duration-200. When the checked prop is true, the cn() call appends translate-x-[25px], moving the thumb 25 pixels to the right. When false, it appends translate-x-[3px], settling the thumb on the left edge of the 48-pixel-wide track. The track itself animates between bg-primary and bg-border via transition-colors duration-200. No framer-motion, no animation library — pure Tailwind utilities.
For most production surfaces, yes. The component renders a native button with role="switch" and aria-checked, which is the WAI-ARIA Switch pattern baseline. Screen readers announce the on/off state correctly, Tab reaches the control, and Space and Enter activate it because those are native button keystrokes. The Drivn Switch does not match the exhaustive per-keystroke contract that Radix documents — for a design system requiring that level of audit, the shadcn/ui Switch wrapping @radix-ui/react-switch is the safer pick.
The Switch renders a button, not a form input, so a form submit does not include its value automatically. Three patterns: pair it with react-hook-form using Controller to bridge the checked + onChange API into the form state, drop a hidden <input type="checkbox" name="..." value={checked.toString()} /> next to the Switch and sync the two values, or call the form library setValue from the onChange callback directly. For most Drivn projects the react-hook-form Controller pattern is the cleanest because it keeps the Switch component itself unmodified.