Segmented Control
One value from a short row of buttons — List or Grid, a view, a setting — an indicator sliding to the one checked. A radio group, in the look of the style's tabs.
Usage
Usage
list
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScField, ScLabel, ScSegmentedControl, ScSegmentedControlIndicator, ScSegmentedControlItem,} from '@semantic-components/ui';
/** One value from a short row: the indicator slides to the one checked. The arrows move and check; one Tab stop. */Anatomy
The indicator first, then an item per option: the indicator sits behind the checked one, and slides when another is checked.
import { ScSegmentedControl, ScSegmentedControlIndicator, ScSegmentedControlItem } from '@semantic-components/ui';<div scSegmentedControl [formField]="form.view"> <div scSegmentedControlIndicator></div> <button scSegmentedControlItem value="list">List</button> <button scSegmentedControlItem value="grid">Grid</button></div>The indicator
Measured from the checked item, in the control: --sc-segmented-control-indicator-left, -top, -width, -height (and -right, -bottom) — again when the items resize. It doesn't slide into its first place (data-activation-direction="none"), then slides, saying which way (left, right, up, down); not with reduced motion. While nothing is checked, it has no box.
Keyboard
| Key | Does |
|---|---|
| Tab | Into the control — the checked item, or the first — and out |
| ←→↑↓ | The previous / next item, checked (skipping disabled ones; wrapping, unless loop is off). Read-only: focus only |
| Home / End | The first / last item, checked |
| Space | Checks the item focused |
Accessibility
- A radio group of radio buttons (
aria-checked), named by its field's label oraria-label. Icon-only items needsr-onlytext. - The indicator is decorative: hidden from screen readers.
Examples
Icons
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScSegmentedControl, ScSegmentedControlIndicator, ScSegmentedControlItem,} from '@semantic-components/ui';import { SiTextAlignCenterIcon, SiTextAlignEndIcon, SiTextAlignStartIcon,Vertical
middle
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScField, ScLabel, ScSegmentedControl, ScSegmentedControlIndicator, ScSegmentedControlItem,} from '@semantic-components/ui';
/** orientation="vertical": stacked; the arrows still move both ways. */Disabled
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScField, ScLabel, ScSegmentedControl, ScSegmentedControlIndicator, ScSegmentedControlItem,} from '@semantic-components/ui';
/** The whole control disabled, or one item — skipped by the arrows, not focused, not checked. */Read-only
pro
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScSegmentedControl, ScSegmentedControlIndicator, ScSegmentedControlItem,} from '@semantic-components/ui';
/** readonly: focusable — the arrows move focus — not changed. */@Component({ selector: 'app-read-only-segmented-control-demo',Form
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, FormRoot, form, required } from '@angular/forms/signals';import { ScButton, ScField, ScFieldErrors, ScLabel, ScSegmentedControl, ScSegmentedControlIndicator, ScSegmentedControlItem,RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { ScField, ScLabel, ScSegmentedControl, ScSegmentedControlIndicator, ScSegmentedControlItem,} from '@semantic-components/ui';API reference
Each part takes class, merged over its own (cn: a later class wins). The look is the style's (segmentedControl, as its tabs: the bar, a tab, the selected tab's raised look on the indicator).
| Part | Selector | Description |
|---|---|---|
ScSegmentedControl | div[scSegmentedControl] | The value: role radiogroup. exportAs scSegmentedControl: focus(). |
ScSegmentedControlIndicator | [scSegmentedControlIndicator] | Behind the checked item, sliding to it: its box in CSS variables, data-activation-direction. |
ScSegmentedControlItem | button[scSegmentedControlItem] | A radio button: value, disabled. data-checked, data-unchecked. |
| Input | Type | Default | Description |
|---|---|---|---|
value | T | null | null | Two-way, or [formField]. null: none checked. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | In a row or stacked; the arrows move both ways in each. |
loop | boolean | true | The arrows wrap. |
disabled, readonly, required, invalid, touched | boolean | false | Bound by [formField]. |