Toggle Group
Coordinate single or multiple pressed controls. Custom element
<ui-toggle-group selection="single" orientation="horizontal" attached aria-label="Text alignment"> <button class="ui-button ui-toggle" type="button" value="left" aria-pressed="true">Left</button> <button class="ui-button ui-toggle" type="button" value="center" aria-pressed="false">Center</button> <button class="ui-button ui-toggle" type="button" value="right" aria-pressed="false">Right</button></ui-toggle-group>Install
import '@timelessui/components/css/tokens.css'import '@timelessui/components/css/button.css'import '@timelessui/components/css/toggle.css'import '@timelessui/components/define/ui-toggle-group'Anatomy
Parts are authored in your own markup and identified by the selector below, so your CSS can target the same anatomy without loading Timeless styles. Required parts must be present for the component to work. Private data-ui-internal-* hooks are written by the runtime and must never be authored.
<ui-toggle-group>
| Part | Required | Selector | Purpose |
|---|---|---|---|
item | Yes | button[aria-pressed] | One toggle button. Author value and aria-pressed; Timeless keeps the pressed set in sync. |
Attributes
Every value below is implemented by the stylesheets this component ships. Boolean attributes are presence-based: author the attribute with no value, or omit it.
<ui-toggle-group>
| Attribute | Values | Default | Description |
|---|---|---|---|
attached | presence | absent | Present to join the buttons into one segmented control. Styling only, resolved by toggle.css. |
orientation | horizontal · vertical | horizontal | Layout and arrow-key axis. |
selection | single · multiple | single | Whether pressing one button releases the others (single) or toggles independently (multiple). |
ui-toggle
| Attribute | Values | Default | Description |
|---|---|---|---|
data-ui-variant | primary · secondary · outline · ghost · danger · danger-outline · link | primary | Visual intent, resolved by button.css. Author class="ui-button ui-toggle" so the shared button styling applies. |
data-ui-size | sm · md · lg | md | Control height, padding, and font size. Resolved by button.css. |
Element API
Attributes above are the authoring surface. These are the DOM properties and events the registered element adds once it upgrades.
<ui-toggle-group>
| Property | Type | Notes |
|---|---|---|
orientation | 'horizontal' | 'vertical' | Reflects the orientation attribute, documented above. |
selection | 'single' | 'multiple' | Reflects the selection attribute, documented above. |
| Event | Detail | Description |
|---|---|---|
ui-before-change | CustomEvent<ToggleGroupChangeDetail> | Cancelable proposal dispatched before the pressed set changes. Call preventDefault() to reject the transition and keep the current value. |
ui-change | CustomEvent<ToggleGroupChangeDetail> | Dispatched after the pressed set has changed. Bubbles and is composed. |
State
Native attributes, ARIA, and platform pseudo-classes are authoritative. Style state through the selectors below rather than adding your own state classes.
| State | Source | How to express it |
|---|---|---|
pressed | aria | Author aria-pressed="true" or "false"; never omit it. |
disabled | native | Native disabled. |
Styling
Root identity: ui-toggle-group, ui-toggle. Required stylesheets: tokens.css, button.css, toggle.css.
This component adds no custom properties of its own. Restyle it through the design tokens or your own CSS.
Design tokens this component reads (24)
These are global Atmosphere tokens. Change them once at the theme level rather than per component.
--ui-accent · --ui-accent-soft · --ui-bg-accent · --ui-bg-accent-active · --ui-bg-accent-hover · --ui-bg-control · --ui-bg-control-active · --ui-bg-control-hover · --ui-bg-control-muted · --ui-bg-danger · --ui-bg-danger-active · --ui-bg-danger-hover · --ui-duration-fast · --ui-ease-standard · --ui-fg · --ui-focus · --ui-line · --ui-radius-control · --ui-shadow-control-accent · --ui-shadow-control-active · --ui-shadow-control-danger · --ui-shadow-control-hover · --ui-shadow-outline-control · --ui-space-2
Accessibility
Keep the native elements, roles, and relationships shown in the example. Timeless adds only the state and keyboard coordination the platform does not already provide, and it never supplies your accessible names — those depend on your content.
Follows the Button pattern from the ARIA Authoring Practices Guide.
| Key | Action |
|---|---|
| Arrow keys | Move focus to the previous or next button, following the orientation and skipping disabled ones. |
| Home / End | Move focus to the first or last enabled button. |
| Page Up / Page Down | Jump ten buttons at a time. |
Each button keeps native activation, and aria-pressed carries the state. With selection="single" pressing one button releases the others.
Before JavaScript runs
The markup above is complete and usable on its own: native controls submit, labels associate, and authored ARIA is already correct. Registration adds state synchronisation, focus management, and keyboard coordination on top of it.
More examples
Open Toggle Group in StoryLite for variants, controls, and manual testing.