Toggle
A two-state button that stays pressed until it's pressed again, for formatting, filters or a favorite. It changes how something looks or what shows; it doesn't save a setting.
Ritla scan of this preview: 41 of 41 checks3 breakpointsScanned
Preview
Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.
Installation
Add the component
npx ritla add toggleAlso works with shadcn:
npx shadcn@latest add @ritla/toggleDependencies it brings
@base-ui/react@phosphor-icons/reactOr copy by hand
Installing by hand copies the component's source into your project. The source comes with a Ritla UI license, so the CLI is the short way to the same files.
Usage
import { Toggle } from "@/components/ui/toggle";import { TextBIcon } from "@phosphor-icons/react/ssr";<Toggle iconLeading={TextBIcon}>Bold</Toggle>Examples
Styles, sizes and states
variant is ghost or outline, size is sm (32px) or md (40px). Pressed takes the brand tint with brand text and icon, so the state never rests on color alone. disabled dims the text and icon.
Icon only
With no text, name it with aria-label (and add a Tooltip where it helps). Several independent toggles side by side; to pick one of several, use a Toggle Group. No Italic: Arabic has no italic, and a slanted Arabic word reads as distorted.
API reference
Toggle
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | None | The label (Figma's Show label). Leave it out and add aria-label for an icon-only toggle. |
pressed / defaultPressed | boolean | None | Figma's Pressed. |
onPressedChange | (pressed: boolean) => void | None | When it's pressed or released. |
variant | "ghost" | "outline" | "ghost" | Figma's Style. |
size | "sm" | "md" | "sm" | Figma's Size: 32 or 40px, with a 48px touch target. |
iconLeading | IconComponent | None | Figma's Icon, at the inline start. |
disabled | boolean | None | State = Disabled. |
value | string | None | Its value inside a Toggle Group. |
Accessibility
Keyboard
Keys are written for left-to-right. In right-to-left the arrow keys swap: the one pointing toward the reading direction moves forward.
| Key | Action |
|---|---|
| Space | Presses or releases it. |
| Enter | Presses or releases it too. |
ARIA
- A button with
aria-pressed, so screen readers say pressed or not pressed. The name stays the same in both states. - The touch target is 48px tall at both sizes.
- For a setting that is saved and applies immediately, use a Switch.
Arabic and RTL notes
Mirrors
- The icon sits at the start of the button (the right), the label after it.
Does not mirror
- Formatting icons (Bold, Underline) and the star don't mirror. Directional icons flip on their own through
<Icon>.
- Numerals
- The button has no numbers of its own; any number in the label follows
numerals. - Arabic typography
- The label is
label-14orlabel-16Medium; the button has a fixed height and the Arabic label stays on one line.
Checks it passes
The Ritla checks this component satisfies by construction. Used as documented, it does not bring these defects onto your page.
- Arabic text falling back past the declared font family (measured, declared, or a webfont that failed to load)
- letter-spacing applied to Arabic text (breaks the connected script)
- Clipped text: content wider than its box with overflow hidden and no ellipsis
- Fixed-pixel-width container whose Arabic text exceeds the space