Toggle Group
A set of two-state toggle buttons with roving keyboard focus, variants, sizes, and spacing controls.
Toggle Group organizes a set of two-state buttons into a keyboard-navigable group supporting single or multiple active values. The examples on this page use the Shadcn Rhea style preset.
Preview
Section titled “Preview”<wc-shadcn-toggle-group-root
id="shadcn-tg-hero"
style-profile="rhea"
variant="outline"
multiple
a11y-label="Text formatting"
>
<wc-shadcn-toggle-group-item style-profile="rhea" value="bold">
<wc-lucide-bold-icon aria-hidden="true"></wc-lucide-bold-icon>
<span class="sr-only">Toggle bold</span>
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="italic">
<wc-lucide-italic-icon
aria-hidden="true"
></wc-lucide-italic-icon>
<span class="sr-only">Toggle italic</span>
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="underline"
>
<wc-lucide-underline-icon
aria-hidden="true"
></wc-lucide-underline-icon>
<span class="sr-only">Toggle underline</span>
</wc-shadcn-toggle-group-item>
</wc-shadcn-toggle-group-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#shadcn-tg-hero'), {
styleProfile: 'rhea',
variant: 'outline',
multiple: true,
defaultValue: ['bold'],
});
</script>Installation
Section titled “Installation”Available starting in 0.3.0-rc.1 and later releases. Import the prototypes directly from @proto.ui/prototypes-shadcn/toggle-group and adapt them for your target runtime.
import { ShadcnToggleGroupItem, ShadcnToggleGroupRoot } from '../proto-ui/components/react';
export function Example() { return ( <ShadcnToggleGroupRoot variant="outline" defaultValue={['a']}> <ShadcnToggleGroupItem value="a">A</ShadcnToggleGroupItem> <ShadcnToggleGroupItem value="b">B</ShadcnToggleGroupItem> <ShadcnToggleGroupItem value="c">C</ShadcnToggleGroupItem> </ShadcnToggleGroupRoot> );}Composition
Section titled “Composition”ToggleGroupRoot├── ToggleGroupItem└── ToggleGroupItem- Selection mode: Both
valueanddefaultValueare string arrays (readonly string[]). Withmultiple={false}(default), at most one item stays active and pressing the active item again clears selection. Setmultiple={true}to allow multiple active items. - Controlled updates: Pass
valuefor controlled mode; interactions emitvalueChange({ value: readonly string[] }) without mutating external state directly. - Keyboard & accessibility: Arrow keys move roving focus along the active
orientationwithout toggling selection; pressSpaceorEnterto toggle the focused item. Icon-only items should include visually hidden text (such assr-only) for an accessible label. - Style presets: Supports
vega,nova,maia,lyra,mira,luma,sera,rhea, andnew-york-v4viastyleProfileor an enclosing Style Scope.
Examples
Section titled “Examples”Outline
Section titled “Outline”Use variant="outline" for a bordered style. In single-select mode, activating the selected item again clears the selection.
<wc-shadcn-toggle-group-root
id="shadcn-tg-outline"
style-profile="rhea"
variant="outline"
a11y-label="Message filter"
>
<wc-shadcn-toggle-group-item style-profile="rhea" value="all">
All
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="missed">
Missed
</wc-shadcn-toggle-group-item>
</wc-shadcn-toggle-group-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#shadcn-tg-outline'), {
styleProfile: 'rhea',
variant: 'outline',
defaultValue: ['all'],
});
</script>Use the size prop (sm, default, lg) on Root to scale all items together, or override individual items.
<div class="flex flex-col items-start gap-4">
<wc-shadcn-toggle-group-root
style-profile="rhea"
size="sm"
variant="outline"
a11y-label="Small position selector"
>
<wc-shadcn-toggle-group-item style-profile="rhea" value="top">
Top
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="bottom"
>
Bottom
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="left">
Left
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="right">
Right
</wc-shadcn-toggle-group-item>
</wc-shadcn-toggle-group-root>
<wc-shadcn-toggle-group-root
style-profile="rhea"
size="default"
variant="outline"
a11y-label="Default position selector"
>
<wc-shadcn-toggle-group-item style-profile="rhea" value="top">
Top
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="bottom"
>
Bottom
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="left">
Left
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="right">
Right
</wc-shadcn-toggle-group-item>
</wc-shadcn-toggle-group-root>
<wc-shadcn-toggle-group-root
style-profile="rhea"
size="lg"
variant="outline"
a11y-label="Large position selector"
>
<wc-shadcn-toggle-group-item style-profile="rhea" value="top">
Top
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="bottom"
>
Bottom
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="left">
Left
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="right">
Right
</wc-shadcn-toggle-group-item>
</wc-shadcn-toggle-group-root>
</div>Spacing
Section titled “Spacing”Use spacing to control item gaps. Modern presets default to 2; set spacing={0} to join items into a continuous bar with collapsed interior borders and profile-matched outer corners.
<div class="flex flex-col items-start gap-4">
<wc-shadcn-toggle-group-root
style-profile="rhea"
size="sm"
variant="outline"
spacing="2"
a11y-label="Spaced position selector"
>
<wc-shadcn-toggle-group-item style-profile="rhea" value="top">
Top
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="bottom"
>
Bottom
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="left">
Left
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="right">
Right
</wc-shadcn-toggle-group-item>
</wc-shadcn-toggle-group-root>
<wc-shadcn-toggle-group-root
style-profile="rhea"
size="sm"
variant="outline"
spacing="0"
a11y-label="Joined position selector"
>
<wc-shadcn-toggle-group-item style-profile="rhea" value="top">
Top
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="bottom"
>
Bottom
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="left">
Left
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="right">
Right
</wc-shadcn-toggle-group-item>
</wc-shadcn-toggle-group-root>
</div>Vertical
Section titled “Vertical”Set orientation="vertical" to stack items vertically and switch roving focus to the vertical arrow keys.
<wc-shadcn-toggle-group-root
id="shadcn-tg-vertical"
style-profile="rhea"
orientation="vertical"
spacing="1"
multiple
a11y-label="Vertical text formatting"
>
<wc-shadcn-toggle-group-item style-profile="rhea" value="bold">
<wc-lucide-bold-icon aria-hidden="true"></wc-lucide-bold-icon>
<span class="sr-only">Toggle bold</span>
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="italic">
<wc-lucide-italic-icon
aria-hidden="true"
></wc-lucide-italic-icon>
<span class="sr-only">Toggle italic</span>
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="underline"
>
<wc-lucide-underline-icon
aria-hidden="true"
></wc-lucide-underline-icon>
<span class="sr-only">Toggle underline</span>
</wc-shadcn-toggle-group-item>
</wc-shadcn-toggle-group-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#shadcn-tg-vertical'), {
styleProfile: 'rhea',
orientation: 'vertical',
spacing: 1,
multiple: true,
defaultValue: ['bold', 'italic'],
});
</script>Disabled
Section titled “Disabled”Set disabled on Root to disable the entire group, or on an individual Item.
<wc-shadcn-toggle-group-root
style-profile="rhea"
variant="outline"
disabled
a11y-label="Disabled formatting controls"
>
<wc-shadcn-toggle-group-item style-profile="rhea" value="bold">
<wc-lucide-bold-icon aria-hidden="true"></wc-lucide-bold-icon>
<span class="sr-only">Toggle bold</span>
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item style-profile="rhea" value="italic">
<wc-lucide-italic-icon
aria-hidden="true"
></wc-lucide-italic-icon>
<span class="sr-only">Toggle italic</span>
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="underline"
>
<wc-lucide-underline-icon
aria-hidden="true"
></wc-lucide-underline-icon>
<span class="sr-only">Toggle underline</span>
</wc-shadcn-toggle-group-item>
</wc-shadcn-toggle-group-root>Custom
Section titled “Custom”Compose ToggleGroup with Field, controlled value, and valueChange to build a custom font weight selector.
<wc-shadcn-field-root style-profile="rhea" class="w-fit">
<wc-shadcn-field-label style-profile="rhea">
Font Weight
</wc-shadcn-field-label>
<wc-shadcn-toggle-group-root
id="font-weight-group"
style-profile="rhea"
variant="outline"
spacing="2"
size="lg"
a11y-label="Font weight"
>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="light"
class="flex size-16 flex-col items-center justify-center gap-0.5 rounded-xl"
>
<span class="text-2xl leading-none font-light">Aa</span>
<span class="text-xs text-muted-foreground">Light</span>
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="normal"
class="flex size-16 flex-col items-center justify-center gap-0.5 rounded-xl"
>
<span class="text-2xl leading-none font-normal">Aa</span>
<span class="text-xs text-muted-foreground">Normal</span>
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="medium"
class="flex size-16 flex-col items-center justify-center gap-0.5 rounded-xl"
>
<span class="text-2xl leading-none font-medium">Aa</span>
<span class="text-xs text-muted-foreground">Medium</span>
</wc-shadcn-toggle-group-item>
<wc-shadcn-toggle-group-item
style-profile="rhea"
value="bold"
class="flex size-16 flex-col items-center justify-center gap-0.5 rounded-xl"
>
<span class="text-2xl leading-none font-bold">Aa</span>
<span class="text-xs text-muted-foreground">Bold</span>
</wc-shadcn-toggle-group-item>
</wc-shadcn-toggle-group-root>
<wc-shadcn-field-description style-profile="rhea">
Use
<span
id="weight-token"
class="rounded-md bg-muted px-1 py-0.5 font-mono text-xs"
>
font-normal
</span>
to set the font weight.
</wc-shadcn-field-description>
</wc-shadcn-field-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const group = document.querySelector('#font-weight-group');
const token = document.querySelector('#weight-token');
let selected = 'normal';
setElementProps(group, {
styleProfile: 'rhea',
value: [selected],
});
group.addEventListener('valueChange', (event) => {
const next = event.detail.value[0];
if (!next) return;
selected = next;
setElementProps(group, {
styleProfile: 'rhea',
value: [selected],
});
token.textContent = 'font-' + selected;
});
</script>| Prop | Type | Default |
|---|---|---|
value | readonly string[] | — (controlled) |
defaultValue | readonly string[] | [] |
multiple | boolean | false |
variant | 'default' 'outline' | 'default' |
size | 'default' 'sm' 'lg' | 'default' |
spacing | 0 1 2 | 2 (modern); 0 (new-york-v4) |
orientation | 'horizontal' 'vertical' | 'horizontal' |
disabled | boolean | false |
readOnly | boolean | false |
loop | boolean | true |
a11yLabel | string | '' |
styleProfile | ShadcnStyleChoice | 'inherit' → scope → 'nova' |
valueChange | Event<{ value: readonly string[] }> | — |
| Prop | Type | Default |
|---|---|---|
value | string | '' (unique in group) |
disabled | boolean | false |
variant | 'default' 'outline' | inherits Root |
size | 'default' 'sm' 'lg' | inherits Root |
styleProfile | ShadcnStyleChoice | 'inherit' → scope → 'nova' |