Skip to content
Logic2BUI

Search docs

Search components and documentation

New
Menu

Toggle

A two-state button that can be either on or off.

Installation

npx logic2b@next add toggle

Usage

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-pressed so its on/off state is announced.
  • Toggle with Space or Enter when focused; reachable with Tab.
  • Icon-only toggles need an aria-label to 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.

View JSON

Toggle

Component
Props: React.ComponentProps<typeof TogglePrimitive.Root> & VariantProps<typeof toggleVariants>
PropTypeRequiredDefaultDescription
variantnull | "default" | "outline"No——
sizenull | "default" | "sm" | "lg"No——

toggleVariants

Utility
(props?: (ConfigVariants<{ variant: { default: string; outline: string; }; size: { default: string; sm: string; lg: string; }; }> & ClassProp) | undefined): string

Accessibility contract

Machine-readable behavior and consumer responsibilities for toggle.

View JSON
Support
Primitive-managed
Pattern
toggle button
Radix Toggle
Keyboard interactions for toggle
KeysBehavior
Enter SpaceActivate the focused control.

Built-in semantics

  • Exposes pressed state through aria-pressed.

Consumer responsibilities

  • Icon-only toggles require an aria-label describing the action.