Copy to clipboard
<div class="flex items-center gap-2">
<Switch id="airplane-mode" />
<Label for="airplane-mode">Airplane Mode</Label>
</div>
<div class="flex items-center gap-2">
<Switch id="airplane-mode" />
<Label for="airplane-mode">Airplane Mode</Label>
</div><div class="flex items-center gap-2">
<Switch id="airplane-mode" />
<Label for="airplane-mode">Airplane Mode</Label>
</div>
Installation
pnpm install @vds-testing/react @vds-testing/stylespnpm install @vds-testing/elements @vds-testing/stylesSee Installation for CSS setup.
Usage
React:
import { Switch } from "@vds-testing/react"<Switch id="mode" />Web Components:
<script type="module">
import "@vds-testing/elements";
</script>
<vds-switch id="mode"></vds-switch>Examples
Checked
Copy to clipboard
<div class="flex items-center gap-2">
<Switch id="notifications" checked />
<Label for="notifications">Enable notifications</Label>
</div>
<div class="flex items-center gap-2">
<Switch id="notifications" checked />
<Label for="notifications">Enable notifications</Label>
</div><div class="flex items-center gap-2">
<Switch id="notifications" checked />
<Label for="notifications">Enable notifications</Label>
</div>
Disabled
Copy to clipboard
<div class="flex items-center gap-2">
<Switch id="disabled" disabled />
<Label for="disabled" class="opacity-50">Disabled switch</Label>
</div>
<div class="flex items-center gap-2">
<Switch id="disabled" disabled />
<Label for="disabled" class="opacity-50">Disabled switch</Label>
</div><div class="flex items-center gap-2">
<Switch id="disabled" disabled />
<Label for="disabled" class="opacity-50">Disabled switch</Label>
</div>
With description
Copy to clipboard
Receive emails about new products and updates.
<div class="flex items-start gap-2">
<Switch id="marketing" class="mt-1" />
<div class="grid gap-1">
<Label for="marketing">Marketing emails</Label>
<p class="vds-paragraph-s text-muted-foreground">Receive emails about new products and updates.</p>
</div>
</div>
<div class="flex items-start gap-2">
<Switch id="marketing" class="mt-1" />
<div class="grid gap-1">
<Label for="marketing">Marketing emails</Label>
<p class="vds-paragraph-s text-muted-foreground">Receive emails about new products and updates.</p>
</div>
</div><div class="flex items-start gap-2">
<Switch id="marketing" class="mt-1" />
<div class="grid gap-1">
<Label for="marketing">Marketing emails</Label>
<p class="vds-paragraph-s text-muted-foreground">Receive emails about new products and updates.</p>
</div>
</div>
Anatomy
Switch- A single toggle element
Props
Switch
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | - | Element ID for label association |
| name | string | - | Form field name |
| checked | boolean | false | Controlled checked state (React) |
| defaultChecked | boolean | false | Uncontrolled initial state (React) |
| disabled | boolean | false | Disables the switch |
| onCheckedChange | (checked: boolean) => void | - | React callback when the value changes |
| class / className | string | - | Additional CSS classes |
Focus uses focus-shape (yellow/black outline) for the track.