Skip to content

Toggle

Get Ritla UI

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

Open in Figma

Preview

Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.

PreviewCode
EnglishMirroredArabic
LTR →

Installation

  1. Add the component

    npx ritla add toggle

    Also works with shadcn: npx shadcn@latest add @ritla/toggle

  2. Dependencies it brings

    @base-ui/react@phosphor-icons/react

  3. Or 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

toggle.tsx
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.

EnglishMirroredArabic
LTR →

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.

EnglishMirroredArabic
LTR →

API reference

Toggle

PropTypeDefaultDescription
childrenReactNodeNoneThe label (Figma's Show label). Leave it out and add aria-label for an icon-only toggle.
pressed / defaultPressedbooleanNoneFigma's Pressed.
onPressedChange(pressed: boolean) => voidNoneWhen 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.
iconLeadingIconComponentNoneFigma's Icon, at the inline start.
disabledbooleanNoneState = Disabled.
valuestringNoneIts 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.

KeyAction
SpacePresses or releases it.
EnterPresses 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-14 or label-16 Medium; 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.

  • R050Arabic text falling back past the declared font family (measured, declared, or a webfont that failed to load)
  • R051letter-spacing applied to Arabic text (breaks the connected script)
  • R042Clipped text: content wider than its box with overflow hidden and no ellipsis
  • R043Fixed-pixel-width container whose Arabic text exceeds the space