✦ Asteria UI
Components

Toggle Group

A set of two or more toggle buttons that allows users to choose one option from a group.

Installation

npx asteria-ui add toggle-group

Usage

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

<ToggleGroup defaultValue="day">
  <ToggleGroupItem value="day">Day</ToggleGroupItem>
  <ToggleGroupItem value="week">Week</ToggleGroupItem>
  <ToggleGroupItem value="month">Month</ToggleGroupItem>
</ToggleGroup>

Examples

Sizes

Disabled item

API reference

ToggleGroup

PropTypeDefaultDescription
size"sm" | "md" | "lg""md"Item size, propagated to every ToggleGroupItem via context.
defaultValuestringUncontrolled initial selected value.
valuestringControlled selected value — pair with onValueChange.
onValueChange(value: string) => voidCalled when the selected item changes.

ToggleGroupItem

PropTypeDefaultDescription
valuestringUnique identifier for this item.
size"sm" | "md" | "lg"Overrides the size inherited from the parent ToggleGroup.
disabledbooleanfalsePrevents selecting this item.

Accessibility

Accessibility

  • Roles. Built on Radix RadioGroup underneath, so it gets the exact contract a segmented control needs: role="radiogroup" on the group, role="radio" with aria-checked on each item.

  • Keyboard. Arrow keys move between items; the newly-focused item is selected automatically (standard radio-group behavior).

  • Disabled items. Rendered as a native disabled button.

  • Focus ring. Visible on Tab via shadow-glow-focus.

When to use

Use as a segmented control for 2–4 mutually exclusive choices — view modes, time ranges, filter categories. Acts like styled radio buttons.

Do:

  • Keep to 2–4 options
  • Use short labels
  • Make the active state visually clear

Don't:

  • Use for 4+ options — use Select or Tabs instead
  • Mix with other form controls
  • Use for triggering actions — use Button instead
  • Tabs — for switching content views
  • Radio Group — for form-style selection
  • Button — for triggering actions