Installation
npx logic2b@next add toggleUsage
import { Toggle } from "@/components/ui/toggle"
<Toggle aria-label="Toggle italic">
<ItalicIcon />
</Toggle>
Usage notes
Built on Radix Toggle.Root with cva variants.
Examples
Outline
With text
Sizes
Accessibility
- Exposes
aria-pressedso its on/off state is announced. - Toggle with
SpaceorEnterwhen focused; reachable withTab. - Icon-only toggles need an
aria-labelto provide an accessible name.
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
Generated JSX
<Toggle
variant="default"
size="default"
>Bold</Toggle>API reference
Generated from the public TypeScript exports in src/ui/toggle.tsx.
Toggle
ComponentProps: React.ComponentProps<typeof TogglePrimitive.Root> & VariantProps<typeof toggleVariants>| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
variant | null | "default" | "outline" | No | — | — |
size | null | "default" | "sm" | "lg" | No | — | — |
toggleVariants
Utility(props?: (ConfigVariants<{ variant: { default: string; outline: string; }; size: { default: string; sm: string; lg: string; }; }> & ClassProp) | undefined): stringAccessibility contract
Machine-readable behavior and consumer responsibilities for toggle.
- Support
- Primitive-managed
- Pattern
- toggle button
- Radix Toggle
| Keys | Behavior |
|---|---|
| Enter Space | Activate the focused control. |
Built-in semantics
- Exposes pressed state through aria-pressed.
Consumer responsibilities
- Icon-only toggles require an aria-label describing the action.