Components

Toggle Group

An animated React toggle group built on shadcn/ui and Radix: the drop-in Toggle and ToggleGroup add smooth transitions and a clear active state — plus a Motion block where the active pill glides between options, for single and multiple selection.

  • Drop-in shadcn API
  • Radix Toggle Group
  • Motion layoutId
  • Single & multiple
  • prefers-reduced-motion

View: grid · Marks: bold

Installation

$ npx shadcn@latest add https://duskui.com/r/toggle-group.json

Also installs components/ui/toggle.tsx (the group reuses its toggleVariants). Both keep shadcn's parts, props and data-slot attributes and animate with CSS only.

Usage

formatting.tsx
import { Bold, Italic, Underline } from "lucide-react"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"

export function Formatting() {
  return (
    <ToggleGroup type="multiple" aria-label="Text formatting">
      <ToggleGroupItem value="bold" aria-label="Bold"><Bold /></ToggleGroupItem>
      <ToggleGroupItem value="italic" aria-label="Italic"><Italic /></ToggleGroupItem>
      <ToggleGroupItem value="underline" aria-label="Underline"><Underline /></ToggleGroupItem>
    </ToggleGroup>
  )
}

Examples

Default

type="multiple" lets several items be on at once. Pressed items get a neutral surface. Arrow keys move between items; Space or Enter toggles.

Outline, single & spacing

variant="outline" joins the items into one bordered bar; type="single" keeps one value. Set spacing to separate them, and size for sm / lg.

Toggle

A single two-state button (components/ui/toggle.tsx) with pressed / onPressedChange, the same variants and sizes.

Blocks

Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.

Animated Toggle Group

Options sit on a recessed track. With type="single" one pill glides to the pressed item (a shared Motion layoutId); with type="multiple" each pressed item gets its own pill that fades in and out. Typed like Radix: value is a string for single and a string array for multiple.

View: grid · Marks: bold

$ npx shadcn@latest add https://duskui.com/r/animated-toggle-group.json
PropTypeDefaultDescription
type"single" | "multiple"—One value or many. Required.
value / onValueChangestring | string[] / (value) => void—Controlled value; a string for single, an array for multiple.
defaultValuestring | string[]—Uncontrolled initial value.
size"sm" | "default" | "lg""default"Item height and padding.
disabled / orientation / rovingFocus / loopRadix ToggleGroup props—Forwarded to the Radix root.
AnimatedToggleGroupItemToggleGroupItem props—An item. Icon-only items need an aria-label.

Animated Toggle Group — sizes

size="sm", default and lg — handy as a chart range picker. Each group gets its own pill, so several can live on one page.

$ npx shadcn@latest add https://duskui.com/r/animated-toggle-group.json

API Reference

Same parts as shadcn/ui: ToggleGroup and ToggleGroupItem (plus Toggle and toggleVariants), each forwarding its Radix props.

PropTypeDefaultDescription
type"single" | "multiple"—On ToggleGroup. Required.
value / onValueChangestring | string[] / (value) => void—Controlled value (string for single, array for multiple).
variant"default" | "outline""default"Ghost items or a bordered bar. Inherited by items.
size"sm" | "default" | "lg""default"Item size. Inherited by items.
spacingnumber0Gap between items in spacing units; 0 joins them.
pressed / onPressedChangeboolean / (pressed: boolean) => void—On Toggle: controlled state.

Accessibility

  • Built on Radix Toggle Group: one Tab stop with roving focus, arrow keys between items, Space / Enter to toggle.
  • Multiple groups expose aria-pressed on each button; single groups use radio semantics (role="radio" + aria-checked).
  • Name the group with aria-label and give icon-only items an aria-label of their own.
  • The gliding pills are decorative (aria-hidden, pointer-events-none).
  • Under prefers-reduced-motion the pills appear and move instantly.