Checkbox Group
Checkboxes sharing one value — the ticked ones — with an optional parent checkbox that ticks them all.
Usage
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScCheckbox, ScCheckboxGroup, ScField } from '@semantic-components/ui';
/** Checkboxes sharing one value: the ticked ones, as an array. */@Component({ selector: 'app-checkbox-group-usage-demo', imports: [ScCheckbox, ScCheckboxGroup, ScField], template: ` <div class="flex flex-col gap-3"> <p id="apples-label" class="text-sm font-medium">Apples</p> <div scCheckboxGroup aria-labelledby="apples-label" [(value)]="apples"> <label scField orientation="horizontal"> <input scCheckbox value="fuji-apple" /> Fuji </label> <label scField orientation="horizontal"> <input scCheckbox value="gala-apple" /> Gala </label> <label scField orientation="horizontal"> <input scCheckbox value="granny-smith-apple" /> Granny Smith </label> </div> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class CheckboxGroupUsageDemo { private readonly apples = signal(['fuji-apple']);}Anatomy
A group round your checkboxes, each with its value; the group holds the ticked ones — a [formField] or [(value)] on the group. A parent checkbox ticks all of allValues.
import { ScCheckbox, ScCheckboxGroup, ScField } from '@semantic-components/ui';<div scCheckboxGroup [formField]="…" [allValues]="…" aria-label="…"> <label scField orientation="horizontal"><input scCheckbox parent /> …</label> <label scField orientation="horizontal"><input scCheckbox value="…" /> …</label></div>Accessibility
- Native checkboxes: each a Tab stop, Space ticks it; a parent is announced as mixed when only some are ticked.
- Name the group: a fieldset's legend round it, aria-labelledby or aria-label; each checkbox by its label.
- Invalid once touched (aria-invalid on its checkboxes).
Examples
Parent checkbox
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScCheckbox, ScCheckboxGroup, ScField } from '@semantic-components/ui';
/** A parent checkbox: ticks all of allValues or none, mixed when only some are. */@Component({ selector: 'app-parent-checkbox-group-demo', imports: [ScCheckbox, ScCheckboxGroup, ScField], template: ` <div scCheckboxGroupNested parent
import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import { ScCheckbox, ScCheckboxGroup, ScField } from '@semantic-components/ui';
/** A parent inside a group: Manage Users heads its own group; the top parent is mixed while it is partly ticked. */@Component({ selector: 'app-nested-parent-checkbox-group-demo', imports: [ScCheckbox, ScCheckboxGroup, ScField], template: ` <div scCheckboxGroupForm
{
"protocols": [
"https"
]
}import { JsonPipe } from '@angular/common';import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form, minLength } from '@angular/forms/signals';import { ScCheckbox, ScCheckboxGroup, ScField, ScFieldDescription, ScFieldset, ScFrame,Disabled
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScCheckbox, ScCheckboxGroup, ScField } from '@semantic-components/ui';
/** A disabled group: every checkbox in it dimmed, out of the Tab order. */@Component({ selector: 'app-disabled-checkbox-group-demo', imports: [ScCheckbox, ScCheckboxGroup, ScField], template: ` <div scCheckboxGroup aria-label="Apples" disabled [(value)]="apples"> <label scField orientation="horizontal">RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { ScCheckbox, ScCheckboxGroup, ScField } from '@semantic-components/ui';
/** In a right-to-left page: the checkboxes at the right, the parent first. */@Component({ selector: 'app-rtl-checkbox-group-demo', imports: [Dir, ScCheckbox, ScCheckboxGroup, ScField], template: ` <div dir="rtl" lang="ar">API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScCheckboxGroup | div[scCheckboxGroup] | role="group"; value: the ticked checkboxes' values, an array (a [formField], or two-way); allValues, for a parent checkbox; disabled. Invalid once touched (focus leaving it). |
ScCheckbox | input[scCheckbox] | In a group: value, its option (any type), ticked in the group's value; or parent, ticking all of allValues or none (mixed when only some are). |