Toggle Group
A set of two-state buttons that can be toggled on or off.
The Toggle Group component is built on top of Kobalte Toggle Group, which provides accessible toggle buttons, keyboard navigation, and focus behavior.
import { Bold, Italic, Underline } from "lucide-solid";
import { ToggleGroup, ToggleGroupItem } from "~/components/ui/toggle-group";
export default function ToggleGroupDemo() { return ( <ToggleGroup variant="outline" multiple> <ToggleGroupItem value="bold" aria-label="Toggle bold"> <Bold /> </ToggleGroupItem> <ToggleGroupItem value="italic" aria-label="Toggle italic"> <Italic /> </ToggleGroupItem> <ToggleGroupItem value="strikethrough" aria-label="Toggle strikethrough"> <Underline /> </ToggleGroupItem> </ToggleGroup> );}Installation
Usage
import { ToggleGroup, ToggleGroupItem } from "~/components/ui/toggle-group";<ToggleGroup defaultValue="a"> <ToggleGroupItem value="a">A</ToggleGroupItem> <ToggleGroupItem value="b">B</ToggleGroupItem> <ToggleGroupItem value="c">C</ToggleGroupItem></ToggleGroup>Composition
Use the following composition to build ToggleGroup:
ToggleGroup├── ToggleGroupItem└── ToggleGroupItemOutline
Use variant="outline" for an outline style.
import { ToggleGroup, ToggleGroupItem } from "~/components/ui/toggle-group";
export default function ToggleGroupOutline() { return ( <ToggleGroup variant="outline" defaultValue="all"> <ToggleGroupItem value="all" aria-label="Toggle all"> All </ToggleGroupItem> <ToggleGroupItem value="missed" aria-label="Toggle missed"> Missed </ToggleGroupItem> </ToggleGroup> );}Size
Use the size prop to change the size of the toggle group.
import { ToggleGroup, ToggleGroupItem } from "~/components/ui/toggle-group";
export default function ToggleGroupSizes() { return ( <div class="flex flex-col gap-4"> <ToggleGroup size="sm" defaultValue="top" variant="outline"> <ToggleGroupItem value="top" aria-label="Toggle top"> Top </ToggleGroupItem> <ToggleGroupItem value="bottom" aria-label="Toggle bottom"> Bottom </ToggleGroupItem> <ToggleGroupItem value="left" aria-label="Toggle left"> Left </ToggleGroupItem> <ToggleGroupItem value="right" aria-label="Toggle right"> Right </ToggleGroupItem> </ToggleGroup> <ToggleGroup defaultValue="top" variant="outline"> <ToggleGroupItem value="top" aria-label="Toggle top"> Top </ToggleGroupItem> <ToggleGroupItem value="bottom" aria-label="Toggle bottom"> Bottom </ToggleGroupItem> <ToggleGroupItem value="left" aria-label="Toggle left"> Left </ToggleGroupItem> <ToggleGroupItem value="right" aria-label="Toggle right"> Right </ToggleGroupItem> </ToggleGroup> </div> );}Spacing
Use spacing to add spacing between toggle group items.
import { ToggleGroup, ToggleGroupItem } from "~/components/ui/toggle-group";
export default function ToggleGroupSpacing() { return ( <ToggleGroup size="sm" defaultValue="top" variant="outline" spacing={2}> <ToggleGroupItem value="top" aria-label="Toggle top"> Top </ToggleGroupItem> <ToggleGroupItem value="bottom" aria-label="Toggle bottom"> Bottom </ToggleGroupItem> <ToggleGroupItem value="left" aria-label="Toggle left"> Left </ToggleGroupItem> <ToggleGroupItem value="right" aria-label="Toggle right"> Right </ToggleGroupItem> </ToggleGroup> );}Vertical
Use orientation="vertical" for vertical toggle groups.
import { Bold, Italic, Underline } from "lucide-solid";
import { ToggleGroup, ToggleGroupItem } from "~/components/ui/toggle-group";
export default function ToggleGroupVertical() { return ( <ToggleGroup multiple orientation="vertical" spacing={1} defaultValue={["bold", "italic"]}> <ToggleGroupItem value="bold" aria-label="Toggle bold"> <Bold /> </ToggleGroupItem> <ToggleGroupItem value="italic" aria-label="Toggle italic"> <Italic /> </ToggleGroupItem> <ToggleGroupItem value="underline" aria-label="Toggle underline"> <Underline /> </ToggleGroupItem> </ToggleGroup> );}Disabled
import { Bold, Italic, Underline } from "lucide-solid";
import { ToggleGroup, ToggleGroupItem } from "~/components/ui/toggle-group";
export default function ToggleGroupDisabled() { return ( <ToggleGroup disabled> <ToggleGroupItem value="bold" aria-label="Toggle bold"> <Bold /> </ToggleGroupItem> <ToggleGroupItem value="italic" aria-label="Toggle italic"> <Italic /> </ToggleGroupItem> <ToggleGroupItem value="strikethrough" aria-label="Toggle strikethrough"> <Underline /> </ToggleGroupItem> </ToggleGroup> );}Custom
A custom toggle group example.
Use font-normal to set the font weight.
import { createSignal } from "solid-js";
import { Field, FieldDescription, FieldLabel } from "~/components/ui/field";import { ToggleGroup, ToggleGroupItem } from "~/components/ui/toggle-group";
export default function ToggleGroupFontWeightSelector() { const [fontWeight, setFontWeight] = createSignal("normal");
return ( <Field> <FieldLabel>Font Weight</FieldLabel> <ToggleGroup value={fontWeight()} onChange={(value) => setFontWeight(value ?? "normal")} variant="outline" spacing={2} size="lg" > <ToggleGroupItem value="light" aria-label="Light" class="flex size-16 flex-col items-center justify-center rounded-xl" > <span class="text-2xl leading-none font-light">Aa</span> <span class="text-xs text-muted-foreground">Light</span> </ToggleGroupItem> <ToggleGroupItem value="normal" aria-label="Normal" class="flex size-16 flex-col items-center justify-center rounded-xl" > <span class="text-2xl leading-none font-normal">Aa</span> <span class="text-xs text-muted-foreground">Normal</span> </ToggleGroupItem> <ToggleGroupItem value="medium" aria-label="Medium" class="flex size-16 flex-col items-center justify-center rounded-xl" > <span class="text-2xl leading-none font-medium">Aa</span> <span class="text-xs text-muted-foreground">Medium</span> </ToggleGroupItem> <ToggleGroupItem value="bold" aria-label="Bold" class="flex size-16 flex-col items-center justify-center rounded-xl" > <span class="text-2xl leading-none font-bold">Aa</span> <span class="text-xs text-muted-foreground">Bold</span> </ToggleGroupItem> </ToggleGroup> <FieldDescription> Use <code class="rounded-md bg-muted px-1 py-0.5 font-mono">font-{fontWeight()}</code> to set the font weight. </FieldDescription> </Field> );}Single vs. multiple selection
By default ToggleGroup only allows a single item to be pressed at a time. In that mode
value/defaultValue are a single string | null and onChange receives string | null.
Pass multiple to allow several items to be pressed at once — in that mode value/defaultValue
are a string[] and onChange receives string[].
// single (default)<ToggleGroup defaultValue="bold" onChange={(value) => console.log(value)}>
// multiple<ToggleGroup multiple defaultValue={["bold"]} onChange={(value) => console.log(value)}>API Reference
For primitive props, keyboard behavior, and accessibility details, see the Kobalte Toggle Group API reference.