- 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
Playground
Every prop, live, and the code it takes.
Content
Variant
Size
Orientation
import { Toggle, ToggleGroup } from "@qeetrix/react";
<ToggleGroup defaultValue={["30d"]} aria-label="Period">
<Toggle value="7d">7 days</Toggle>
<Toggle value="30d">30 days</Toggle>
<Toggle value="90d">90 days</Toggle>
</ToggleGroup>02
One view among a few
segmented, the default: one joined control, one choice. Arrow keys move between them.
<ToggleGroup defaultValue={["grid"]} aria-label="Members view">
<Toggle value="grid" icon={LayoutGridIcon} filledWhenPressed>Grid</Toggle>
<Toggle value="list" icon={ListIcon}>List</Toggle>
</ToggleGroup>03
Controlled
value and onValueChange: keep one pressed, and let the page follow it.
Sign-ins over the last 30 days.
const [period, setPeriod] = useState(["30d"]);
<ToggleGroup value={period} onValueChange={(next) => next.length && setPeriod(next)} aria-label="Sign-in activity period">
<Toggle value="7d">7 days</Toggle>
<Toggle value="30d">30 days</Toggle>
<Toggle value="90d">90 days</Toggle>
</ToggleGroup>04
Several at once
separate and multiple: a set of tools, each on or off.
<ToggleGroup variant="separate" multiple size="sm" aria-label="Formatting">
<Toggle value="bold" icon={BoldIcon} aria-label="Bold" tooltip="Bold (Ctrl+B)" />
<Toggle value="italic" icon={ItalicIcon} aria-label="Italic" tooltip="Italic (Ctrl+I)" />
<Toggle value="underline" icon={UnderlineIcon} aria-label="Underline" tooltip="Underline (Ctrl+U)" />
</ToggleGroup>05
In a toolbar
Tools beside a choice, split by a rule.
<Inline gap="md" align="center">
<ToggleGroup variant="separate" multiple size="sm" aria-label="Formatting">
<Toggle value="bold" icon={BoldIcon} aria-label="Bold" tooltipSide="bottom" />
<Toggle value="italic" icon={ItalicIcon} aria-label="Italic" tooltipSide="bottom" />
<Toggle value="underline" icon={UnderlineIcon} aria-label="Underline" tooltipSide="bottom" />
</ToggleGroup>
<Separator orientation="vertical" />
<ToggleGroup size="sm" defaultValue={["start"]} aria-label="Text alignment">
<Toggle value="start" icon={TextAlignStartIcon} aria-label="Align start" tooltipSide="bottom" />
<Toggle value="center" icon={TextAlignCenterIcon} aria-label="Align centre" tooltipSide="bottom" />
<Toggle value="end" icon={TextAlignEndIcon} aria-label="Align end" tooltipSide="bottom" />
</ToggleGroup>
</Inline>06
Vertical
orientation="vertical": stacked, and the up and down arrows move.
<ToggleGroup orientation="vertical" defaultValue={["name"]} aria-label="Sort by">
<Toggle value="name">Name</Toggle>
<Toggle value="last-sign-in">Last sign-in</Toggle>
<Toggle value="created">Created</Toggle>
</ToggleGroup>