Skip to content

Toggle Group

Download .md

A toggle group is a row of chips that filter the content on the page, such as release statuses, or switch how it shows.

  • Use it for quick filters above a list, with the count in each chip: “Terbit 12”.
  • A status filter always has one value: “Semua” by default, and clicking the active chip keeps it on.
  • Use Tabs when each option shows different content, and a Select for more than five options.
  • Use several-on mode for filters that combine, such as genres.
React
Vue
123
  1. 1Selected chip
  2. 2Chip
  3. 3Group, one value at a time

Chips h-8 on radius-md with a border, 8px apart, never pill-shaped. An active chip is primary-soft with primary-text and a primary-tinted border. An optional count sits after the label in muted-foreground.

Mode Use it for
One on Status filters, view switches.
Several on (multiple) Filters that combine.

The single Toggle (one button that stays pressed) installs with the group and has no page of its own.

React Vue Flutter Type Default Use
multiple type="single" / "multiple" ShadToggleGroup / ShadToggleGroup.multiple mode one on How many chips can be on.
value (array) / onValueChange v-model initialValue / onChanged value none The chips that are on.
keep one on: ignore an empty value keep one on: ignore an empty value allowDeselection: false boolean can be emptied Keeps a status filter from going empty.
variant="outline" variant="outline" ShadToggleVariant.outline text default The chip look.
spacing spacing spacing number 2 (React), 0 (Vue) The gap between chips; 0 joins them. Use 2.
import { useState } from "react"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
const statuses = [
{ value: "all", label: "Semua", count: 24 },
{ value: "published", label: "Terbit", count: 12 },
{ value: "pending", label: "Menunggu", count: 8 },
{ value: "rejected", label: "Ditolak", count: 4 },
]
export default function ToggleGroupDemo() {
const [status, setStatus] = useState("all")
return (
<ToggleGroup
variant="outline"
spacing={2}
aria-label="Filter status"
value={[status]}
// A status filter always has one value: clicking the active chip keeps it on.
onValueChange={(value) => value.length > 0 && setStatus(value[value.length - 1])}
>
{statuses.map((s) => (
<ToggleGroupItem key={s.value} value={s.value}>
{s.label}
<span className="tabular-nums text-muted-foreground">{s.count}</span>
</ToggleGroupItem>
))}
</ToggleGroup>
)
}
Terminal window
npx shadcn@latest add https://design.sosialoka.tech/r/react/toggle-group.json
  • Name the group with aria-label, such as “Filter status”.
  • Each chip says whether it is on with aria-pressed.
  • Arrow keys move between chips; Space and Enter turn one on.
  • Put the count inside the chip, so it is read with the label.