Unified UI

Toggle

A pressable on/off button for binary states like bold, italic, mute, or favorite. Built on Radix UI Toggle.

Overview

The Toggle component is a pressable on/off button for binary toggleable actions. Distinct from Switch — Toggle acts like a button that stays pressed (e.g. bold, italic, mute), while Switch is a sliding track for settings/preferences. Built on Radix UI's Toggle primitive for full accessibility.


Installation

Install the component via the CLI in one command.

npx @work-rjkashyap/unified-ui add toggle
pnpm dlx @work-rjkashyap/unified-ui add toggle
npx @work-rjkashyap/unified-ui add toggle
bunx @work-rjkashyap/unified-ui add toggle

If you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.

Or install the full package

Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.

npm install @work-rjkashyap/unified-ui
pnpm add @work-rjkashyap/unified-ui
yarn add @work-rjkashyap/unified-ui
bun add @work-rjkashyap/unified-ui

Anatomy

import { Toggle } from "@work-rjkashyap/unified-ui";

Examples

Basic Usage

Variants

DefaultOutlineGhost

Sizes

SizeHeightPaddingFont Size
sm32px8px12px
md36px12px14px
lg40px16px14px

With Text Labels

With Icon Props

Default Pressed

Disabled State


Props

PropTypeDefaultDescription
variant"default" | "outline" | "ghost""default"Visual variant of the toggle.
size"sm" | "md" | "lg""md"Size of the toggle.
pressedbooleanControlled pressed state.
defaultPressedbooleanDefault pressed state for uncontrolled usage.
onPressedChange(pressed: boolean) => voidCallback fired when the pressed state changes.
disabledbooleanfalseDisables the toggle.
iconLeftReactNodeIcon rendered before the label.
iconRightReactNodeIcon rendered after the label.
classNamestringAdditional CSS classes.

Accessibility

Icon-only toggles must include an aria-label to be accessible to screen readers.

  • aria-pressed — Radix automatically manages the aria-pressed attribute based on the toggle state.
  • Keyboard — Space and Enter keys toggle the pressed state (handled by Radix).
  • Focus ring — Visible on keyboard navigation via focus-visible.
  • Disabled — Uses both the disabled attribute and Radix's data-disabled for styling.
  • Role — Renders as a <button> with implicit button role.

Toggle vs Switch

FeatureToggleSwitch
Looks likeA button that stays pressedA sliding track with thumb
Best forToolbar actions (bold, italic)Settings and preferences
GroupableYes, via ToggleGroupNo
LabelIcon or text inside the buttonLabel beside the track

Design Tokens

TokenUsage
--mutedHover background
--secondaryPressed state background (default)
--foregroundPressed state text color
--muted-foregroundUnpressed text color
--borderOutline variant border
--border-strongOutline pressed border
--radius-mdBorder radius
--duration-fastTransition speed
--easing-standardEasing curve

On this page