multipleorientationvariantsizedisabledimport { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { AlignCenter, AlignLeft, AlignRight } from "lucide-react"
export function Alignment() {
return (
<ToggleGroup aria-label="Alignment" defaultValue={["center"]}>
<ToggleGroupItem value="left" aria-label="Align left">
<AlignLeft className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="center" aria-label="Align center">
<AlignCenter className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="right" aria-label="Align right">
<AlignRight className="h-4 w-4" />
</ToggleGroupItem>
</ToggleGroup>
)
}Usage
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { AlignCenter, AlignLeft, AlignRight } from "lucide-react"
export function Alignment() {
return (
<ToggleGroup aria-label="Alignment" defaultValue={["left"]}>
<ToggleGroupItem value="left" aria-label="Align left">
<AlignLeft className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="center" aria-label="Align center">
<AlignCenter className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="right" aria-label="Align right">
<AlignRight className="h-4 w-4" />
</ToggleGroupItem>
</ToggleGroup>
)
}Examples
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';
import { AlignLeft, AlignCenter, AlignRight } from 'lucide-react';
export function Example() {
return (
<ToggleGroup defaultValue={["center"]}>
<ToggleGroupItem value="left" aria-label="Align left">
<AlignLeft className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="center" aria-label="Align center">
<AlignCenter className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="right" aria-label="Align right">
<AlignRight className="h-4 w-4" />
</ToggleGroupItem>
</ToggleGroup>
);
}import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';
import { Bold, Italic, Underline } from 'lucide-react';
export function Example() {
return (
<ToggleGroup multiple>
<ToggleGroupItem value="bold" aria-label="Toggle bold">
<Bold className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="italic" aria-label="Toggle italic">
<Italic className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="underline" aria-label="Toggle underline">
<Underline className="h-4 w-4" />
</ToggleGroupItem>
</ToggleGroup>
);
}import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';
import { Bold, Italic } from 'lucide-react';
export function Example() {
return (
<div className="flex flex-col gap-4">
<ToggleGroup multiple>
<ToggleGroupItem value="bold" size="sm" aria-label="Bold">
<Bold className="h-3 w-3" />
</ToggleGroupItem>
<ToggleGroupItem value="italic" size="sm" aria-label="Italic">
<Italic className="h-3 w-3" />
</ToggleGroupItem>
</ToggleGroup>
<ToggleGroup multiple>
<ToggleGroupItem value="bold" size="default" aria-label="Bold">
<Bold className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="italic" size="default" aria-label="Italic">
<Italic className="h-4 w-4" />
</ToggleGroupItem>
</ToggleGroup>
<ToggleGroup multiple>
<ToggleGroupItem value="bold" size="lg" aria-label="Bold">
<Bold className="h-5 w-5" />
</ToggleGroupItem>
<ToggleGroupItem value="italic" size="lg" aria-label="Italic">
<Italic className="h-5 w-5" />
</ToggleGroupItem>
</ToggleGroup>
</div>
);
}Notes
Defaults
Items default to variant="outline" and size="sm"; a standalone Toggle defaults to default for both.
Single mode
Without multiple, pressing an item replaces the value; pressing the pressed item clears it. Read value[0].
API
details.cancel() refuses the change.setValue.Agent
Inside an AgentProvider, it appears in agent.snapshot() as toggle-group.
Reads
labelThe group's aria-label.
valueThe pressed item's label, or a list of labels when multiple.
itemsEvery item's label.
multiplePresent when several items can be pressed.
disabledTrue when the whole group is blocked.
Actions
select("Align center")Picks by label, then by value. Replaces in single mode, adds in multiple. A miss lists the items.
setValue(["Toggle bold", "Toggle italic"])Replaces the whole value. Only when multiple.
An agent's change runs through onValueChange. isAgentChange(details) is true for it, and details.cancel() refuses it; the agent is told the app refused. A disabled item and a disabled group refuse on their own.
await agent.act({
steps: [{ ref: "toggle-group", action: "select", args: ["Align right"] }],
})Accessibility
- The group has role group; each item is a button with aria-pressed.
- Name the group with aria-label. Without one the agent lists it as
toggle-group. - Icon-only items each need an aria-label. The agent reads these as item names.
- Disabled items stay in the group but cannot be pressed.