- Docs
- Components
- Actions
Toggle group
A row of toggles: one view among a few, or a set of tools that are each on or off.
- Import
- @qeetrix/react
- Status
- StableSince 0.0.2
- Renders
<div role="group">Server-rendered- Tested
- WCAG 2.2 AAaxe on every pull request
01
Import
// From the package: a build keeps only what it uses.
import { ToggleGroup, Toggle } from "@qeetrix/react";
// Or from its own path.
import { ToggleGroup, Toggle } from "@qeetrix/react/toggle";02
Props
And every native attribute of the element it renders.
| Prop | Type | Default | What it does |
|---|---|---|---|
value | readonly string[] | — | The pressed values, controlled. |
defaultValue | readonly string[] | — | The pressed values to start with. |
onValueChange | (value, details) => void | — | Called with the pressed values. |
multiple | boolean | false | Several pressed at once; otherwise one at a time. |
variant | "segmented" | "separate" | "segmented" | One joined control, or toggles with a gap. |
size | "sm" | "md" | "lg" | "md" | Every toggle's height; it wins over theirs. |
orientation | "horizontal" | "vertical" | "horizontal" | How they line up, and which arrow keys move. |
fullWidth | boolean | false | Fills its row; every toggle takes an equal share, its label centred. A vertical group ignores it. |
disabled | boolean | false | Disables every toggle. |
aria-label | string | — | What's being chosen: "Members view". |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What it is |
|---|---|---|
toggle-group | <div role="group"> | The root. data-variant, data-size, data-orientation. |
toggle | <button> | Each toggle (see Toggle). data-pressed while on. |
04
Always one pressed
A single-choice group can be emptied by pressing its choice again; keep the last one.
const [period, setPeriod] = useState(["30d"]);
<ToggleGroup value={period} onValueChange={(next) => next.length && setPeriod(next)} aria-label="Period">
<Toggle value="7d">7 days</Toggle>
<Toggle value="30d">30 days</Toggle>
</ToggleGroup>