Loading component…
Loading component…
A row of toggle buttons
To reuse this local React demo, copy all files from the Code tab into the same folder, then import ToggleGroup from ./toggle-group.
import { useState } from "react";
import { ToggleGroup } from "@/components/ui/toggle-group";
export function RunFilters() {
const [status, setStatus] = useState(["running", "needs-you"]);
return (
<ToggleGroup
aria-label="Show runs"
value={status}
onChange={setStatus}
items={[
{ value: "running", label: "Running" },
{ value: "needs-you", label: "Needs you" },
{ value: "done", label: "Done" },
{ value: "failed", label: "Failed" },
]}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| items | ToggleGroupItem[] | { value, label?, icon?, ariaLabel?, disabled? } – give icon-only items an ariaLabel, it's also their tooltip | |
| type | "multiple" \| "single" | "multiple" | multiple: any number can be on, the value is a list · single: at most one, pressing it again turns it off |
| value | string[] \| string \| null | Controlled value – a list with type="multiple", one value or null with type="single" | |
| defaultValue | string[] \| string \| null | Starting value when uncontrolled – nothing on by default | |
| onChange | (value: string[]) => void \| (value: string \| null) => void | Called with the new value; a list keeps the items' order, null when the single item was turned off | |
| variant | "tray" \| "buttons" | "tray" | A light-gray track like the Segmented Control with pressed items raised as white pills, or separate white chips with an edge that wrap onto a new line |
| size | "sm" \| "md" \| "lg" | "md" | 26, 30 or 36px tall (36px+ on touch screens) |
| disabled | boolean | false | Disables every item |
| aria-label | string | Names the group – or use aria-labelledby | |
| className | string | Extra class on the root |
buttons wrap onto a new line when they don't fit; the tray scrolls sideways instead
Long labels end in … rather than pushing past the container
Touch screens get items at least 36px tall
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
@import "tailwindcss"; in your main CSS file.