Toggle Group
Choose among related tool settings.
Examples
Choose among related tool settings
React code
import { ToggleGroup, Toggle } from "@accelerate/react/components";
export function Example() {
return (
<>
<ToggleGroup aria-label="Text alignment">
<Toggle value="left" aria-pressed="true">Left</Toggle>
<Toggle value="center" aria-pressed="false">Center</Toggle>
<Toggle value="right" aria-pressed="false">Right</Toggle>
</ToggleGroup>
</>
);
}Angular code
import { Component } from "@angular/core";
import { AccToggleGroup, AccToggle } from "@accelerate/angular/components";
@Component({
selector: "app-example",
imports: [
AccToggleGroup,
AccToggle,
],
template: `
<div accToggleGroup aria-label="Text alignment">
<button accToggle value="left" aria-pressed="true">Left</button>
<button accToggle value="center" aria-pressed="false">Center</button>
<button accToggle value="right" aria-pressed="false">Right</button>
</div>
`,
})
export class Example {}Multiple selections
React code
import { ToggleGroup, Toggle } from "@accelerate/react/components";
export function Example() {
return (
<>
<ToggleGroup aria-label="Formatting" data-multiple="">
<Toggle value="bold">Bold</Toggle>
<Toggle value="italic">Italic</Toggle>
</ToggleGroup>
</>
);
}Angular code
import { Component } from "@angular/core";
import { AccToggleGroup, AccToggle } from "@accelerate/angular/components";
@Component({
selector: "app-example",
imports: [
AccToggleGroup,
AccToggle,
],
template: `
<div accToggleGroup aria-label="Formatting" data-multiple="">
<button accToggle value="bold">Bold</button>
<button accToggle value="italic">Italic</button>
</div>
`,
})
export class Example {}Installation
Source preview. The expanded component catalog is ahead of the public npm releases. To run these examples in your own application, use packages built from the SDK source used for the previews or a release that includes the APIs below.
- React
@accelerate/ui@0.4.0and@accelerate/react@0.4.0- Angular
@accelerate/ui@0.4.0and@accelerate/angular@0.2.0
Load @accelerate/ui/theme.css and put acc-theme on the app or the region using Accelerator components. See the framework setup guide for the theme and adapter conventions.
Usage
Compose valued Toggle buttons. Use data-multiple for independent selection and data-orientation="vertical" for vertical navigation. Reports the activated button value.
Import the React component ToggleGroup from @accelerate/react/components. For Angular, add AccToggleGroup to the standalone component’s imports and use <div accToggleGroup>.
Examples use these React parts: ToggleGroup, Toggle. The Angular examples show the corresponding directives and template hosts.
API reference
- data-multiple
- Allows more than one pressed button.
- data-orientation
- Sets keyboard navigation direction.
- valueChange
- Reports the activated button’s value.