apps/design-system/content/docs/components/switch.mdx
npx shadcn-ui@latest add switch
<Step>Install the following dependencies:</Step>
npm install @radix-ui/react-switch
<Step>Copy and paste the following code into your project.</Step>
<ComponentSource name="switch" /><Step>Update the import paths to match your project setup.</Step>
</Steps> </TabsContent> </Tabs>import { Switch } from '@/components/ui/switch'
<Switch />
When using Switch in custom flex layouts (especially with height constraints like h-full), you may need to add relative positioning to the parent container to ensure proper rendering of focus rings, form validation messages, and overflow.
<div className="relative">
<FormField_Shadcn_
control={form.control}
name="enabled"
render={({ field }) => (
<FormControl_Shadcn_>
<Switch checked={field.value} onCheckedChange={field.onChange} />
</FormControl_Shadcn_>
)}
/>
</div>
You don’t need to add relative manually when using FormItemLayout as it provides the necessary positioning context automatically.