Toggle Group
Introduction
Section titled “Introduction”A named group of toggle buttons for one setting with a few choices, such as text alignment, a list or grid view, or text styles. Each item is a native button with aria-pressed (Button with pressed). Single selection keeps at most one item pressed (and with required, exactly one); multiple lets several be pressed. One button is in the tab sequence and the arrow keys move between the buttons (roving tabindex).
- Single or multipleWorks like a radio group or like a set of independent toggles.
- Required selectionOptionally keeps at least one item pressed at all times.
- Icons and labelsItems show text, an icon, or only an icon with the label as its name.
- Keyboard friendlyArrow keys move between items and Space or Enter toggles them.
Use it for
- Switching a view or a formatting state that applies at once: list or grid, bold and italic, alignment.
- Two to about seven short choices shown side by side.
Use something else for
- A form value submitted with other fields: use Radio Group or Checkbox Group.
- Navigation between panels: use Tabs.
- Commands that run once: use Button or Button Group.
Anatomy
<div class="aui-toggle-group [--vertical] [--attached]" role="group" aria-label="Text alignment"> <button class="aui-toggle-group__item aui-button [aui-button--pressed]" aria-pressed="true|false" tabindex="0|-1">icon label</button> ...</div>Live example
Section titled “Live example”Use the bar above each frame to switch theme, density, direction, and locale.
Toggle Group in the Buttons and toolbars showcase
Section titled “Toggle Group in the Buttons and toolbars showcase”The part of the Buttons and toolbars showcase that uses Toggle Group. Change its options, use it with the keyboard, and watch the event log; the link in the frame opens the full showcase. The bar above the frame switches theme, density, direction, and locale.
Showcase source
// Buttons showcase: every variant and size, icons, loading and disabled states,// toggle buttons, a button group, and toggle groups, with live options and an event log.import { Button } from '@absoluteui/components/button';import { ButtonGroup } from '@absoluteui/components/button-group';import { ToggleGroup } from '@absoluteui/components/toggle-group';import { choice, createShowcase, hostIn, section, toggle } from './kit.js';
type Size = 'sm' | 'md' | 'lg';
const sc = createShowcase({ title: 'Buttons and toolbars', description: 'Variants, sizes, icons, loading, toggle buttons, a button group, and toggle groups as one editor toolbar.',});
const variants = section(sc, 'Variants', ['button']);const row = (parent: HTMLElement): HTMLElement => { const r = hostIn(parent); r.className = 'sc-row'; return r;};const variantRow = row(variants);const all: Button[] = [];for (const variant of ['primary', 'secondary', 'outline', 'ghost', 'danger'] as const) { const b = Button.create({ text: `${variant.charAt(0).toUpperCase()}${variant.slice(1)}`, variant }, document); variantRow.append(b.element); b.element.addEventListener('click', () => { sc.log(`button click`, { variant }); }); all.push(b);}
const icons = section(sc, 'Icons', ['button']);const iconRow = row(icons);const save = Button.create({ text: 'Save', icon: 'check', variant: 'primary' }, document);const download = Button.create({ text: 'Download', icon: 'download', iconPosition: 'end' }, document);const remove = Button.create({ icon: 'trash', label: 'Delete', variant: 'danger' }, document);const more = Button.create({ icon: 'more-horizontal', label: 'More actions', variant: 'ghost' }, document);iconRow.append(save.element, download.element, remove.element, more.element);all.push(save, download, remove, more);save.element.addEventListener('click', () => { // A save shows the loading state for a moment; the button stays focusable. save.setLoading(true); sc.log('save started'); setTimeout(() => { save.setLoading(false); sc.log('save finished'); }, 1200);});
const toggles = section(sc, 'Toggle buttons', ['button']);const toggleRow = row(toggles);const pin = Button.create({ text: 'Pin', icon: 'locate', pressed: false }, document);const mute = Button.create({ text: 'Mute', pressed: true, variant: 'outline' }, document);toggleRow.append(pin.element, mute.element);all.push(pin, mute);sc.listen(pin.element, ['aui-change'], 'pin');sc.listen(mute.element, ['aui-change'], 'mute');
const toolbar = section(sc, 'Editor toolbar', ['button-group', 'toggle-group']);const toolbarRow = row(toolbar);const history = ButtonGroup.create(hostIn(toolbarRow), { label: 'History', attached: true, buttons: [ { icon: 'undo', label: 'Undo', value: 'undo' }, { icon: 'redo', label: 'Redo', value: 'redo' }, ],});const formatting = ToggleGroup.create(hostIn(toolbarRow), { label: 'Formatting', multiple: true, attached: true, value: ['bold'], items: [ { value: 'bold', label: 'Bold', icon: 'bold', iconOnly: true }, { value: 'italic', label: 'Italic', icon: 'italic', iconOnly: true }, { value: 'underline', label: 'Underline', icon: 'underline', iconOnly: true }, ],});const alignment = ToggleGroup.create(hostIn(toolbarRow), { label: 'Alignment', required: true, attached: true, value: ['start'], items: [ { value: 'start', label: 'Align start', icon: 'align-start', iconOnly: true }, { value: 'center', label: 'Align center', icon: 'align-center', iconOnly: true }, { value: 'end', label: 'Align end', icon: 'align-end', iconOnly: true }, ],});const view = ToggleGroup.create(hostIn(toolbarRow), { label: 'View', required: true, value: ['edit'], items: [ { value: 'edit', label: 'Edit' }, { value: 'preview', label: 'Preview' }, ],});sc.listen(history.element, ['aui-action'], 'history');sc.listen(formatting.host, ['aui-change'], 'formatting');sc.listen(alignment.host, ['aui-change'], 'alignment');sc.listen(view.host, ['aui-change'], 'view');
choice<Size>( sc, 'Size', [ { value: 'sm', label: 'Small' }, { value: 'md', label: 'Medium' }, { value: 'lg', label: 'Large' }, ], 'md', (size) => { for (const b of all) b.update({ size }); for (const g of [history, formatting, alignment, view]) g.update({ size }); },);toggle(sc, 'Disabled', false, (disabled) => { for (const b of all) b.update({ disabled }); for (const g of [formatting, alignment, view]) g.update({ disabled }); history.update({ buttons: [{ icon: 'undo', label: 'Undo', value: 'undo', disabled }, { icon: 'redo', label: 'Redo', value: 'redo', disabled }] });});toggle(sc, 'Loading', false, (loading) => { for (const b of [save, download]) b.setLoading(loading);}, ['button']);toggle(sc, 'Attached groups', true, (attached) => { for (const g of [history, formatting, alignment]) g.update({ attached });}, ['button-group', 'toggle-group']);Required single choice with icon-only buttons
Section titled “Required single choice with icon-only buttons”import { ToggleGroup } from '@absoluteui/components/toggle-group';
const host = document.createElement('div');document.body.append(host);ToggleGroup.create(host, { label: 'Text alignment', required: true, attached: true, value: ['start'], items: [ { value: 'start', label: 'Align start', icon: 'align-start', iconOnly: true }, { value: 'center', label: 'Align center', icon: 'align-center', iconOnly: true }, { value: 'end', label: 'Align end', icon: 'align-end', iconOnly: true }, ],});Multiple text styles
Section titled “Multiple text styles”import { ToggleGroup, type ToggleGroupChangeDetail } from '@absoluteui/components/toggle-group';
const host = document.createElement('div');const preview = document.createElement('p');preview.textContent = 'The quick brown fox';document.body.append(host, preview);ToggleGroup.create(host, { label: 'Text style', multiple: true, items: [ { value: 'bold', label: 'Bold', icon: 'bold' }, { value: 'italic', label: 'Italic', icon: 'italic' }, { value: 'underline', label: 'Underline', icon: 'underline' }, ],});host.addEventListener('aui-change', (event) => { const { value } = (event as CustomEvent<ToggleGroupChangeDetail>).detail; preview.style.fontWeight = value.includes('bold') ? 'bold' : ''; preview.style.fontStyle = value.includes('italic') ? 'italic' : ''; preview.style.textDecoration = value.includes('underline') ? 'underline' : '';});Install and start
Section titled “Install and start”npm install @absoluteui/components @absoluteui/core @absoluteui/themeRegistry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.
import { ToggleGroup } from '@absoluteui/components/toggle-group';import '@absoluteui/components/button/style.css';import '@absoluteui/components/toggle-group/style.css';First use
Section titled “First use”import { ToggleGroup } from '@absoluteui/components/toggle-group';import '@absoluteui/components/button/style.css';import '@absoluteui/components/toggle-group/style.css';
const host = document.querySelector<HTMLElement>('#density');if (host) ToggleGroup.create(host, { label: 'Density', required: true, value: ['comfortable'], items: [{ value: 'compact', label: 'Compact' }, { value: 'comfortable', label: 'Comfortable' }] });More usage
import { ToggleGroup, type ToggleGroupChangeDetail } from '@absoluteui/components/toggle-group';
const host = document.querySelector<HTMLElement>('#view');if (host) { ToggleGroup.create(host, { label: 'View', required: true, attached: true, value: ['list'], items: [{ value: 'list', label: 'List' }, { value: 'grid', label: 'Grid' }] }); host.addEventListener('aui-change', (event) => { const [view] = (event as CustomEvent<ToggleGroupChangeDetail>).detail.value; document.body.dataset.view = view ?? 'list'; });}Using Angular? See Toggle Group for Angular.
API reference
Section titled “API reference”Factory
Section titled “Factory”ToggleGroup.create(host: HTMLElement, options: ToggleGroupOptions): ToggleGroupGlobal configuration key: toggleGroup (see Configuration).
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
label |
string |
Accessible name of the group. Required. | |
items |
readonly ToggleGroupItem[] |
Buttons: { value, label, icon?, iconOnly?, disabled? } (1 to 100, unique values). Required. | |
value |
readonly string[] |
Pressed values; at most one in single mode. | |
multiple |
boolean |
"false" |
Allow several pressed items. |
required |
boolean |
"false" |
Single mode: one item stays pressed. |
orientation |
'horizontal' | 'vertical' |
"horizontal" |
Layout and arrow-key axis. |
attached |
boolean |
"false" |
Join the buttons into one segmented control. |
disabled |
boolean |
"false" |
Disable every button. |
size |
'sm' | 'md' | 'lg' |
"md" |
Button size. Globally configurable. |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
host |
HTMLElement |
The host element (role=group). |
value |
readonly string[] |
Pressed values, in item order. |
options |
Readonly<ToggleGroupOptions> |
Current options. |
Methods
Section titled “Methods”| Method | Description |
|---|---|
setValue(value: readonly string[]): void |
Set the pressed values (no event). |
focus(): void |
Focus the button in the tab sequence. |
update(options: Partial<ToggleGroupOptions>): void |
Merge and apply options; new items re-create the buttons. |
destroy(): void |
Destroy the buttons and remove attributes, classes, and listeners. |
Events
Section titled “Events”| Event | Detail | Bubbles | Cancelable | Description |
|---|---|---|---|---|
aui-change |
ToggleGroupChangeDetail |
Yes | No | The user changed the pressed items: { value, changed }. |
CSS classes
Section titled “CSS classes”All rules live in the aui.components cascade layer, so application styles override them without specificity battles.
| Class | Purpose |
|---|---|
aui-toggle-group |
Host (role=group). |
aui-toggle-group--vertical |
Vertical orientation. |
aui-toggle-group--attached |
Segmented control. |
aui-toggle-group__item |
Each button (also aui-button). |
Design tokens
Section titled “Design tokens”Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.
--aui-border-width | --aui-radius-md | --aui-space-1
TypeScript definitions
interface ToggleGroupConfig { size: 'sm' | 'md' | 'lg' }interface ToggleGroupItem { value: string; label: string; icon?: IconRef | null; iconOnly?: boolean; disabled?: boolean }interface ToggleGroupOptions extends Partial<ToggleGroupConfig> { label: string; items: readonly ToggleGroupItem[]; value?: readonly string[]; multiple?: boolean; required?: boolean; orientation?: 'horizontal' | 'vertical'; attached?: boolean; disabled?: boolean;}interface ToggleGroupChangeDetail { value: string[]; changed: string }Accessibility and performance
Section titled “Accessibility and performance”Accessibility
Section titled “Accessibility”Pattern: WAI-ARIA toggle buttons (button with aria-pressed) in a named group, with roving tabindex as in the APG toolbar pattern.
Checked on every docs build: the showcase passes axe (WCAG 2.2 A and AA rules) in the default, dark, and high-contrast themes and right to left; the playground loads without errors and passes axe before and after every on/off option is switched, with no Content Security Policy violations.
Keyboard
Section titled “Keyboard”| Key | Context | Action |
|---|---|---|
| Tab | Group | Moves focus into the group (to the last focused button) and out of it. |
| ArrowRight / ArrowLeft | Horizontal | Move to the next or previous enabled button (reading direction aware, wraps). |
| ArrowDown / ArrowUp | Vertical | Move to the next or previous enabled button (wraps). |
| Home / End | Group | Move to the first or last enabled button. |
| Enter / Space | Item | Toggle the button. |
| Element | Role |
|---|---|
| host | group |
| item | button (native) with aria-pressed |
ARIA attributes
Section titled “ARIA attributes”| Attribute | Element | Value |
|---|---|---|
aria-label |
host | the label option |
aria-pressed |
item | true when pressed, false otherwise |
aria-orientation |
host | vertical when vertical |
aria-label |
icon-only item | the item label |
One button in the tab sequence (roving tabindex); clicking a button makes it the tab stop.
WCAG 2.2 success criteria addressed
Section titled “WCAG 2.2 success criteria addressed”| Criterion | Level | Note |
|---|---|---|
| 1.3.1 Info and Relationships | A | |
| 1.4.1 Use of Color | A | |
| 2.1.1 Keyboard | A | |
| 2.4.3 Focus Order | A | |
| 4.1.2 Name, Role, Value | A |
Automated test results: Accessibility and compliance.
Notes and known caveats
Section titled “Notes and known caveats”- The pressed state differs in more than hue (selection fill and a stronger boundary) and is exposed with aria-pressed.
- Required single groups keep one button pressed; pressing it again does nothing.
- Manual screen-reader verification (NVDA, JAWS, VoiceOver) is pending.
Performance
Section titled “Performance”| Import cost | Minified | gzip | brotli | CSS brotli |
|---|---|---|---|---|
@absoluteui/components/toggle-group |
40.6 kB | 14.1 kB | 12.5 kB | 0.4 kB |
Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.
| Budget (enforced in CI) | Limit |
|---|---|
| ToggleGroup.create with 5 items | < 2 ms average in headless Chromium |
Tested scale: Up to 100 items accepted; intended for a handful.
Pressing updates the state of each button in place; only new items re-create buttons.
Measured run times: Performance.
Details
Section titled “Details”States
Single or multiple; required; horizontal or vertical; attached; disabled; item disabled; pressed items.
State transitions
| From | Trigger | To |
|---|---|---|
| single, A pressed | user presses B | B pressed, A released; aui-change |
| single, A pressed | user presses A | none pressed (or unchanged when required) |
| multiple | user presses an item | it toggles; others unchanged |
| any | setValue() / update({ value }) |
the given values, no event |
Accessibility notes
- Keep item labels the same whether pressed or not;
aria-pressedannounces the state. - The pressed state differs in more than hue: a selection fill and a stronger boundary.
- The e2e axe run covers three themes; manual screen-reader verification is pending.
Responsive behavior
Buttons wrap unless attached; vertical stacks them.
Right-to-left
Arrow keys follow the reading direction; attached radii use logical properties.
Theming
Button tokens apply; pressed colors come from the selection tokens (contrast gate pairs). Forced colors draw pressed buttons in Highlight.
Global configuration
configureAbsoluteUI({ components: { toggleGroup: { size: 'sm' } } });Component configuration
The instance size overrides configuration; configuration changes re-render existing groups.
Icons
Per item icon; with iconOnly, the label becomes the accessible name.
Security
Labels are rendered as text, never parsed as HTML.
Data handling
No persistence, network access, or telemetry.
Supported data scale
Up to 100 items; intended for a handful.
Edge cases
requiredwith an emptyvaluepresses the first enabled item.- A disabled item keeps its pressed state; the arrow keys skip it.
- Values not among the items are rejected.
Errors
| Code | Category | Cause |
|---|---|---|
TOGGLE_GROUP_OPTIONS |
configuration | Blank label, no items or more than 100, duplicate or blank values, a blank item label, unknown values, or several values in single mode. |
ICON_UNKNOWN |
configuration | Unknown item icon. |
CFG_INVALID_VALUE / CFG_UNKNOWN_OPTION |
configuration | Invalid size or unknown configuration. |
Invalid options throw before the host is modified.
Known limitations
- Not a form control: the value is not submitted with a form.
- Manual screen-reader verification is pending.
Unsupported scenarios
- Menus or popups inside the group.
- Rich content in items.
(c) 2026 Kasadara Technology Solutions Pvt Ltd. AbsoluteUI is free to use under the AbsoluteUI Free Use License; it is not open source.