Components
Toggle
A two-state button that can be on or off.
Loading...
Installation
npx shadcn@latest add @fujin/toggleUsage
import { Toggle } from "@/components/ui/toggle"<Toggle aria-label="Bold" pressed={bold} onPressedChange={setBold}>
<BoldIcon />
</Toggle>An icon-only toggle needs an aria-label naming the thing being toggled
("Bold"), not the action ("Make bold"). The pressed state is announced from
aria-pressed, which Base UI sets for you.
What's different from shadcn/ui
renderreplacesasChild, from Base UI - same asbutton.- Hover changes only the text colour. In the default theme
--accentand--mutedare the same colour, so shadcn's hover and pressed backgrounds are identical and clicking a hovered toggle shows no change. Here the pressed background is the only background. - The unpressed label is
muted-foreground, so pressing also darkens the foreground rather than relying on a near-white background alone. - Solid 2px focus ring instead of
ring-ring/50(WCAG 1.4.11). - Style the pressed state with
data-[pressed]:(Base UI), notdata-[state=on]:(Radix).
API Reference
Prop
Type
toggleVariants is exported for styling other elements (toggle-group uses
it). Every other prop is forwarded to the Base UI
Toggle.