Toggle Group

Toggles sharing one value: one pressed at a time, or several. In the look of the app's style.

Buttons & ActionsExperimental

Usage

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScToggleGroup, ScToggleGroupItem } from '@semantic-components/ui';import {  SiBoldIcon,  SiItalicIcon,  SiUnderlineIcon,} from '@semantic-icons/lucide-icons';
/** Several pressed at a time (multiple): bold, italic, underline. */@Component({  selector: 'app-toggle-group-usage-demo',  imports: [    ScToggleGroup,    ScToggleGroupItem,    SiBoldIcon,    SiItalicIcon,    SiUnderlineIcon,  ],  template: `    <div      scToggleGroup      variant="outline"      multiple      aria-label="Text formatting"      [(value)]="formatting"    >      <button scToggleGroupItem value="bold">        <svg siBoldIcon></svg>        <span class="sr-only">Bold</span>      </button>      <button scToggleGroupItem value="italic">        <svg siItalicIcon></svg>        <span class="sr-only">Italic</span>      </button>      <button scToggleGroupItem value="underline">        <svg siUnderlineIcon></svg>        <span class="sr-only">Underline</span>      </button>    </div>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class ToggleGroupUsageDemo {  private readonly formatting = signal<string[]>([]);}

Anatomy

A group round your buttons, each with its value; the group holds the pressed ones — a [formField] or [(value)], an array. Inside a toolbar, use a widget group in the toolbar: it shares the toolbar's arrow keys.

import { ScToggleGroup, ScToggleGroupItem } from '@semantic-components/ui';
<div scToggleGroup [formField]="…" aria-label="…">  <button scToggleGroupItem value="…">…</button></div>

Accessibility

  • One Tab stop: the arrow keys move between the items (← and → mirrored right to left; ↑ and ↓ when vertical), Home and End to the ends; Space and Enter press one.
  • Each item a button with aria-pressed; its name stays the same as it toggles — its text, or an icon with sr-only text.
  • Name the group: aria-label or aria-labelledby.
  • The keyboard follows Base UI's toggle group (role="group", the CDK's FocusKeyManager), not Angular Aria's Toolbar: a toolbar is its own component (scToolbar), with its widget group (scToolbarWidgetGroup) sharing the toolbar's Tab stop and arrow keys. You choose: a toggle group on its own, or a toolbar.

Examples

Outline

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScToggleGroup, ScToggleGroupItem } from '@semantic-components/ui';
/** variant="outline": the items joined in a border. */@Component({  selector: 'app-outline-toggle-group-demo',  imports: [ScToggleGroup, ScToggleGroupItem],  template: `    <div scToggleGroup variant="outline" aria-label="Calls" [(value)]="calls">      <button scToggleGroupItem value="all">All</button>

Sizes

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScToggleGroup, ScToggleGroupItem } from '@semantic-components/ui';
/** size: sm, default, lg — for every item. */@Component({  selector: 'app-sizes-toggle-group-demo',  imports: [ScToggleGroup, ScToggleGroupItem],  template: `    <div class="flex flex-col gap-4">      <div

Spacing

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScToggleGroup, ScToggleGroupItem } from '@semantic-components/ui';
/** spacing: the gap between the items (2 by default; 0 joins them). */@Component({  selector: 'app-spacing-toggle-group-demo',  imports: [ScToggleGroup, ScToggleGroupItem],  template: `    <div class="flex flex-col gap-4">      <div

Vertical

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScToggleGroup, ScToggleGroupItem } from '@semantic-components/ui';import {  SiBoldIcon,  SiItalicIcon,  SiUnderlineIcon,} from '@semantic-icons/lucide-icons';
/** orientation="vertical": stacked; Up and Down move between the items. */@Component({

Disabled

import { Component, ViewEncapsulation } from '@angular/core';import { ScToggleGroup, ScToggleGroupItem } from '@semantic-components/ui';import {  SiBoldIcon,  SiItalicIcon,  SiUnderlineIcon,} from '@semantic-icons/lucide-icons';
/** A disabled group: every item dimmed, out of the Tab order. */@Component({

Font weight

Font Weight

Use font-normal for your text.

import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import {  ScFrame,  ScToggleGroup,  ScToggleGroupItem,} from '@semantic-components/ui';
/** Big items, each a sample and its name: one weight at a time. */@Component({  selector: 'app-font-weight-toggle-group-demo',

Items added later

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScButton,  ScToggleGroup,  ScToggleGroupItem,} from '@semantic-components/ui';
/** Items that come later, anywhere in the group: the keys follow the page's order. */@Component({  selector: 'app-added-later-toggle-group-demo',

Single

Alignment: start

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScToggleGroup, ScToggleGroupItem } from '@semantic-components/ui';import {  SiTextAlignCenterIcon,  SiTextAlignEndIcon,  SiTextAlignStartIcon,} from '@semantic-icons/lucide-icons';
/** One pressed at a time — or none: pressing it again releases it. */@Component({

Multiple

Formatting: bold

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScToggleGroup, ScToggleGroupItem } from '@semantic-components/ui';import {  SiBoldIcon,  SiItalicIcon,  SiUnderlineIcon,} from '@semantic-icons/lucide-icons';
/** Several pressed at a time: the value lists them. */@Component({

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { ScToggleGroup, ScToggleGroupItem } from '@semantic-components/ui';
/** In a right-to-left page: the first item at the right; the arrows mirrored. */@Component({  selector: 'app-rtl-toggle-group-demo',  imports: [Dir, ScToggleGroup, ScToggleGroupItem],  template: `    <div dir="rtl" lang="ar">

API reference

Each part takes class, merged over the style (cn: a later class wins).

PartSelectorDescription
ScToggleGroupdiv[scToggleGroup] role="group"; value: the pressed items' values, an array (a [formField], or two-way); multiple; variant, size, spacing (2; 0 joins them) and orientation for its items; loopFocus; disabled.
ScToggleGroupItembutton[scToggleGroupItem] A toggle in the group: value (any type), pressed when the group's value includes it (aria-pressed); disabled. In the style's toggle look.