TuMarca

Switch

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

stable
Tipo: ui
Versión: 1.0.0
forms switch toggle form input

Comparación entre la versión Astro (Saastro) y React (shadcn/ui)

🚀 saastro/ui (Astro)
⚛️ shadcn/ui (React)

Installation

Usage

---
import { Switch } from "@/components/ui-saastro/switch"
import { Label } from "@/components/ui-saastro/label"
---

<div class="flex items-center space-x-2">
  <Switch id="airplane-mode" />
  <Label for="airplane-mode">Airplane Mode</Label>
</div>

Examples

Default

<Switch />

Checked by Default

<Switch checked />

Disabled

<Switch disabled />

With Form

<form>
  <div class="flex items-center space-x-2">
    <Switch id="marketing" name="marketing" />
    <Label for="marketing">Receive marketing emails</Label>
  </div>
</form>

Props

PropTypeDefaultDescription
checkedbooleanfalseWhether the switch is checked
disabledbooleanfalseWhether the switch is disabled
idstring-The id for the underlying input
namestring-The name for form submission
classstring-Additional CSS classes

Accessibility

  • Uses native checkbox input for built-in accessibility
  • Visually styled as a switch toggle
  • Supports keyboard navigation (Space to toggle)
  • Properly conveys checked state to screen readers