Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Toggle Group

A set of two-state buttons that can be toggled on or off.

Installation

pnpm add @heyramzi/ui bits-ui

Usage

import * as ToggleGroup from "@heyramzi/ui/shadcn/toggle-group";
<ToggleGroup.Root type="multiple" variant="outline">
  <ToggleGroup.Item value="bold" aria-label="Toggle bold">B</ToggleGroup.Item>
  <ToggleGroup.Item value="italic" aria-label="Toggle italic">I</ToggleGroup.Item>
</ToggleGroup.Root>

Keyboard and accessibility

Key Does
Tab Moves focus into the group, then out of it. The group is one stop.
Arrow Right Moves focus to the next item.
Arrow Left Moves focus to the previous item.
Home Moves focus to the first item.
End Moves focus to the last item.
Space Enter Turns the focused item on or off.
  • With type="single" each item is a radio that reports checked. With type="multiple" each one reports pressed.
  • Focus loops from the last item back to the first unless loop is false.
  • Arrow keys only move focus. Nothing changes until you press Space or Enter.

API reference

ToggleGroup.Root

variant "default" | "outline"
Default "default"
size "default" | "sm" | "lg"
Default "default"
spacing number
Default 0
ref bindable HTMLElement | null
Default null
value bindable ToggleGroup.Root
class string
...rest
Every prop of ToggleGroup.Root from bits-ui
Prop Type Default
variant "default" | "outline" "default"
size "default" | "sm" | "lg" "default"
spacing number 0
ref bindable HTMLElement | null null
value bindable ToggleGroup.Root
class string
...rest Every prop of ToggleGroup.Root from bits-ui

ToggleGroup.Item

variant "default" | "outline"
Default "default"
size "default" | "sm" | "lg"
Default "default"
ref bindable HTMLElement | null
Default null
value bindable ToggleGroup.Item
class string
...rest
Every prop of ToggleGroup.Item from bits-ui
Prop Type Default
variant "default" | "outline" "default"
size "default" | "sm" | "lg" "default"
ref bindable HTMLElement | null null
value bindable ToggleGroup.Item
class string
...rest Every prop of ToggleGroup.Item from bits-ui