Skip to main content
  1. Docs
  2. Components
  3. 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

toggle-group.tsx
// 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.

PropTypeDefaultWhat it does
valuereadonly string[]—The pressed values, controlled.
defaultValuereadonly string[]—The pressed values to start with.
onValueChange(value, details) => void—Called with the pressed values.
multiplebooleanfalseSeveral 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.
fullWidthbooleanfalseFills its row; every toggle takes an equal share, its label centred. A vertical group ignores it.
disabledbooleanfalseDisables every toggle.
aria-labelstring—What's being chosen: "Members view".

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat 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.

period.tsx
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>
Next — Toggle groupAccessibility