Toggle
A two-state button. When it is on it fills with the primary color, so the state is clear. Small and default are 44px; large is 48px.
Installation
npx shadcn@latest add @sevenone/toggleUsage
import { Toggle } from "@/components/ui/toggle"Examples
Default
<Toggle aria-label="Bold">
<Bold />
</Toggle>
<Toggle aria-label="Italic" defaultPressed>
<Italic />
</Toggle>Outline, sizes and text
<Toggle variant="outline" size="sm" aria-label="Bold"><Bold /></Toggle>
<Toggle variant="outline" aria-label="Italic"><Italic /></Toggle>
<Toggle variant="outline" size="lg" aria-label="Underline"><Underline /></Toggle>
<Toggle variant="outline">
<Italic />
Italic
</Toggle>Accessibility
- Screen readers announce it as a toggle button with its pressed state.
- Icon-only toggles need an aria-label.
- The on state changes the fill, not only a color tint, so it is clear for everyone.