Skip to content
Logic2BUI

Search docs

Search components and documentation

New
Menu

Toggle Group

A set of two-state buttons that can be toggled on or off.

Installation

npx logic2b@next add toggle-group

Usage

import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

<ToggleGroup type="multiple">
  <ToggleGroupItem value="bold" aria-label="Toggle bold">
    <BoldIcon />
  </ToggleGroupItem>
</ToggleGroup>

Usage notes

Built on Radix ToggleGroup. The group’s variant and size are shared with every ToggleGroupItem through context.

Examples

Single selection

Sizes

Accessibility

  • With type="single" items behave as a radio group; Arrow keys move selection between them.
  • With type="multiple" each item toggles independently and exposes aria-pressed.
  • Tab moves focus into the group, then Arrow keys move between items; icon-only items need an aria-label.

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
<ToggleGroup
  type="single"
  defaultValue="center"
  variant="outline"
  size="default"
  aria-label="Text alignment"
>
  <ToggleGroupItem
    value="left"
    aria-label="Align left"
  >Left</ToggleGroupItem>
  <ToggleGroupItem
    value="center"
    aria-label="Align center"
  >Center</ToggleGroupItem>
  <ToggleGroupItem
    value="right"
    aria-label="Align right"
  >Right</ToggleGroupItem>
</ToggleGroup>

API reference

Generated from the public TypeScript exports in src/ui/toggle-group.tsx.

View JSON

ToggleGroup

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

ToggleGroupItem

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

Accessibility contract

Machine-readable behavior and consumer responsibilities for toggle-group.

View JSON
Support
Primitive-managed
Pattern
toggle group
Radix Toggle Group
Keyboard interactions for toggle-group
KeysBehavior
ArrowUp ArrowDown ArrowLeft ArrowRightMove within the composite control.
Enter SpaceActivate the focused control.

Built-in semantics

  • Uses roving focus and pressed/selected state for single or multiple selection.

Consumer responsibilities

  • Label the group and every icon-only item.