Button Toggle
A segmented single-select — one-of-N choices rendered as a row of connected buttons. Form-associated, holds the selected value, and follows the WAI-ARIA radiogroup pattern with arrow-key navigation.
Preview
<esa-button-toggle label="View" id="bt-preview"></esa-button-toggle>
<script>
el.options = [
{ value: 'list', label: 'List' },
{ value: 'grid', label: 'Grid' },
{ value: 'map', label: 'Map' },
];
el.value = 'grid';
</script> import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@esa/ecology/esa-button-toggle';
@Component({
selector: 'app-button-toggle-demo',
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<esa-button-toggle label="View" id="bt-preview" [options]="options" [value]="value"></esa-button-toggle>
`,
})
export class ButtonToggleDemo {
options = [
{ value: 'list', label: 'List' },
{ value: 'grid', label: 'Grid' },
{ value: 'map', label: 'Map' },
];
value = 'grid';
} Sizes
Four sizes share the form scale. Default is md.
<esa-button-toggle size="xs"></esa-button-toggle>
<esa-button-toggle size="sm"></esa-button-toggle>
<esa-button-toggle size="md"></esa-button-toggle>
<esa-button-toggle size="lg"></esa-button-toggle> import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@esa/ecology/esa-button-toggle';
@Component({
selector: 'app-button-toggle-demo',
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<esa-button-toggle size="xs"></esa-button-toggle>
<esa-button-toggle size="sm"></esa-button-toggle>
<esa-button-toggle size="md"></esa-button-toggle>
<esa-button-toggle size="lg"></esa-button-toggle>
`,
})
export class ButtonToggleDemo {} Icons
Each option may carry an icon — inner Lucide SVG markup (the same paths convention as esa-icon). It renders before the label and inherits currentColor, so it flips to the inverse color on the selected segment.
el.options = [
{ value: 'grid', label: 'Grid', icon: "<rect width='18' height='18' x='3' y='3' rx='2'/>…" },
{ value: 'kanban', label: 'Kanban', icon: "<path d='M3 3h18v18H3z'/>…" },
{ value: 'timeline', label: 'Timeline', icon: "<path d='M8 2v4'/>…" },
]; Omit label for an icon-only segment — set ariaLabel so it still has an accessible name.
el.options = [
{ value: 'grid', icon: "<rect …/>", ariaLabel: 'Grid' },
{ value: 'kanban', icon: "<path …/>", ariaLabel: 'Kanban' },
{ value: 'timeline', icon: "<path …/>", ariaLabel: 'Timeline' },
]; States
error-text replaces help-text in the slot below the group
and reddens the track — the same one-slot precedence esa-select and
esa-text-field use, so the two messages never stack.
<esa-button-toggle label="Default"></esa-button-toggle>
<esa-button-toggle label="With help" help-text="Pick a layout"></esa-button-toggle>
<esa-button-toggle label="With error" error-text="Choose a layout to continue"></esa-button-toggle>
<esa-button-toggle label="Disabled" disabled></esa-button-toggle> import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@esa/ecology/esa-button-toggle';
@Component({
selector: 'app-button-toggle-demo',
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<esa-button-toggle label="Default"></esa-button-toggle>
<esa-button-toggle label="With help" help-text="Pick a layout"></esa-button-toggle>
<esa-button-toggle label="With error" error-text="Choose a layout to continue"></esa-button-toggle>
<esa-button-toggle label="Disabled" disabled></esa-button-toggle>
`,
})
export class ButtonToggleDemo {} Form participation
The control submits its selected value under its name. Submitting logs the view entry.
With required, the group reports valueMissing through
ElementInternals until something is selected, so the native form
refuses to submit and checkValidity() returns false —
the asterisk is not the whole of it.
<form>
<esa-button-toggle name="view" label="View"></esa-button-toggle>
<button type="submit">Submit</button>
</form> import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@esa/ecology/esa-button-toggle';
@Component({
selector: 'app-button-toggle-demo',
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<form>
<esa-button-toggle name="view" label="View"></esa-button-toggle>
<button type="submit">Submit</button>
</form>
`,
})
export class ButtonToggleDemo {} API
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | '' | Optional visible label above the group; becomes the radiogroup name. |
help-text | string | '' | Helper text below the group. Property: `helpText`. |
error-text | string | '' | Validation message below the group. Replaces help-text and reddens the track. Property: `errorText`. |
options | EsaToggleOption[] | [] | The segments. Set as a property (an array, not an attribute). Optional icon is inner Lucide SVG markup (the same paths convention as esa-icon), rendered before the label and inheriting currentColor. Omit label for an icon-only segment, but then set ariaLabel for its accessible name. |
value | string | '' | Selected option's value. Single-select; bound to the form value. |
size | 'xs' | 'sm' | 'md' | 'lg' | 'md' | Control size (shared form scale). |
name | string | undefined | — | Form field name — the key this control submits under. |
disabled | boolean | false | Disables every segment. |
required | boolean | false | Blocks submission while nothing is selected (valueMissing), and adds an asterisk plus aria-required. |
Events
| Event | Type | Default | Description |
|---|---|---|---|
change | CustomEvent<{ value: string }> | — | Fired when the selection changes. Composed and bubbling; detail.value is the newly selected value. |
Binding these events from Angular
Every one of these is a CustomEvent, so the payload is on
$event.detail — $event.target.value reads empty, with no
error. The names are lowercase and Angular passes them to
addEventListener verbatim, so camel-casing one means it never fires.
(change)="onChange($event.detail)"
Accessibility
- Renders
role="radiogroup"wrappingrole="radio"buttons witharia-checkedreflecting selection. - Roving tabindex: only the selected (or first) segment is tab-reachable; Arrow keys move selection through the group, wrapping at the ends.
HomeandEndjump to the first and last segments; Enter and Space select the focused segment.- The
labelbecomes the group's accessible name viaaria-labelledby. - Visible focus ring on the active segment via
--focus-ring-*tokens; the focused segment is raised so its ring sits above neighbors. - Best for small fixed option sets — past about six options, prefer a select.
Theming surface
Every public token this component reads, extracted from its source at build time,
split by blast radius: the hooks that belong to this component,
then the shared and system tokens it consumes alongside everything else. The
Resolves to column walks each token's real lineage —
component → semantic → primitive → raw value — so you
can see exactly where re-pointing it lands. A spoke re-skins by overriding these in
its theme-<slug>.css; component internals are never edited. No
hook for what you need? File it with /request-lego.
Type roles it names
This component does not set a size, weight, face or tracking of its own — it names a composite, and the composite carries all five. A composite is a class rather than a token, so none of it appears in the tables below; re-theme text by re-pointing the token family, not by editing the component.
| Role | Re-point | Reach |
|---|---|---|
.typography-body-sm |
| +20 more componentsesa-alert-box, esa-breadcrumbs, esa-card, esa-checkbox-group, esa-combobox, esa-command-palette, esa-date-picker, esa-empty-state, esa-file-upload, esa-form-field, esa-input-tag, esa-link-column, esa-loading-overlay, esa-progress-bar, esa-radio-group, esa-search-panel, esa-select, esa-stat, esa-text-field, esa-textarea |
.typography-label-2xs |
| +11 more componentsesa-checkbox-group, esa-color-picker, esa-combobox, esa-date-picker, esa-form-field, esa-input-tag, esa-progress-bar, esa-radio-group, esa-range-slider, esa-text-field, esa-textarea |
.typography-label-lg |
| +12 more componentsesa-breadcrumbs, esa-checkbox-group, esa-color-picker, esa-combobox, esa-date-picker, esa-form-field, esa-input-tag, esa-radio-group, esa-range-slider, esa-select, esa-text-field, esa-textarea |
.typography-label-md |
| +33 more componentsesa-app-bar, esa-breadcrumbs, esa-button-group, esa-card, esa-checkbox-group, esa-color-picker, esa-combobox, esa-command-palette, esa-confirm-dialog, esa-danger-zone, esa-date-picker, esa-dialog, esa-empty-state, esa-entity-search, esa-file-upload, esa-filter-container, esa-form-field, esa-header-nav, esa-input-tag, esa-link-column, esa-page-header, esa-pillbox, esa-popover, esa-progress-bar, esa-radio-group, esa-range-slider, esa-select, esa-side-dialog, esa-sidebar-nav, esa-stat, esa-text-field, esa-textarea, esa-tooltip |
.typography-label-xs |
| +14 more componentsesa-breadcrumbs, esa-checkbox-group, esa-color-picker, esa-combobox, esa-date-picker, esa-entity-search, esa-form-field, esa-input-tag, esa-progress-bar, esa-radio-group, esa-range-slider, esa-select, esa-text-field, esa-textarea |
.typography-microcopy-2xs |
| +3 more componentsesa-button, esa-pill, esa-range-slider |
.typography-microcopy-2xs-strong |
| +2 more componentsesa-badge, esa-chip-group |
.typography-microcopy-lg |
| +2 more componentsesa-button, esa-range-slider |
.typography-microcopy-lg-strong |
| +1 more componentesa-chip-group |
.typography-microcopy-md |
| +4 more componentsesa-button, esa-pill, esa-range-slider, esa-sidebar-nav |
.typography-microcopy-md-strong |
| +2 more componentsesa-badge, esa-chip-group |
.typography-microcopy-xs |
| +6 more componentsesa-app-shell, esa-button, esa-filter-pills, esa-kbd, esa-pill, esa-range-slider |
.typography-microcopy-xs-strong |
| +5 more componentsesa-badge, esa-chip-group, esa-filter-dropdown, esa-sidebar-nav, esa-tab-layout |
Wired to this component
None. This component has no hooks of its own — it themes entirely through the shared tokens below, so every override here also moves its siblings.
Shared tokens it reads
Owned by a family or by the semantic layer. Still overridable — but scope the
override (esa-foo { --form-border-color: … }) unless you mean to move
everything that reads it. Reach says what else that is.
| Token | Reach | Resolves to |
|---|---|---|
--focus-ring-color | component focus ring group · +34 more | #3e9b4f via --color-border-default-focus → --color-grass-10 |
--focus-ring-offset | component focus ring group · +31 more | 2px |
--focus-ring-width | component focus ring group · +35 more | 2px via --border-width-focus → --border-width-200 |
--form-border-color | component forms group · +11 more | one role per property, so a theme can move the ring's weight and its colour independently. Tier 3's --focus-ring-width now reads this instead of holding a bare 2px, which is the same shape --focus-ring-color has always had (a thin tier-3 alias over a tier-2 role) — width was simply never given the tier-2 half.
*
* This role was rejected once, and the rejection is worth recording because its PREMISE was wrong rather than its reasoning. The argument against an `emphasis` width was that every 2px border in the kit is micro-geometry — spinner rings, the kbd keycap lip, a chevron. The focus ring was not in that enumeration and does not fit it: 33 components render it, more than read any other tier-3 token, and it is not micro-geometry but an accessibility affordance whose weight is a legitimate brand axis (a spoke that needs a heavier ring for contrast has to be able to reach it). It is also not a `border` in any component — every consumer paints it with `outline` or `box-shadow` — which is precisely why a survey of BORDERS missed it. The name still says `border` because tier 2 already calls the ring's colour --color-border-default-focus via --color-border-default |
--form-border-width | component forms group · +10 more | 1px via --border-width-default → --border-width-100 |
--form-error-border-color | component forms group · +9 more | #ce2c31 via --color-background-utility-danger → --color-red-11 |
--form-error-color | component forms group · +9 more | #ce2c31 via --color-content-utility-danger → --color-red-11 |
--form-help-color | component forms group · +9 more | #646464 via --color-content-default-secondary → --color-gray-11 |
--form-label-color | component forms group · +7 more | #646464 via --color-content-default-secondary → --color-gray-11 |
--color-background-elevation-raised | semantic every component | #fcfcfc via --color-gray-1 |
--color-background-elevation-sunken | semantic every component | #f0f0f0 via --color-gray-3 |
--color-background-overlay-hover | semantic every component | rgba(0, 0, 0, 0.03) |
--color-content-brand | semantic every component | #2a7e3b via --color-grass-11 |
--color-content-default | semantic every component | #202020 via --color-gray-12 |
--color-content-default-secondary | semantic every component | #646464 via --color-gray-11 |
--color-content-disabled | semantic every component | #8d8d8d via --color-gray-9 |
--color-content-utility-danger | semantic every component | #ce2c31 via --color-red-11 |
--radius-md | semantic every component | 0.5rem via --radius-200 |
--radius-sm | semantic every component | 0.25rem via --radius-100 |
--transition-fast | semantic every component | 150ms via --duration-150 |
--spacing-100 | primitive every component | 0.25rem |
--spacing-150 | primitive every component | 0.375rem |
--spacing-200 | primitive every component | 0.5rem |
--spacing-250 | primitive every component | 0.625rem |
--spacing-300 | primitive every component | 0.75rem |
--spacing-400 | primitive every component | 1rem |