Skip to main content
  1. Docs
  2. Components
  3. Actions

Toggle

A tool that's pressed or not. With only an icon, its name shows as its tooltip.

Import
@qeetrix/react
Status
StableSince 0.0.2
Renders
<button aria-pressed>Server-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

Import

toggle.tsx
// From the package: a build keeps only what it uses.
import { Toggle } from "@qeetrix/react";

// Or from its own path.
import { Toggle } from "@qeetrix/react/toggle";

02

Props

And every native attribute of the element it renders.

PropTypeDefaultWhat it does
pressedboolean—Pressed, controlled.
defaultPressedbooleanfalsePressed to start with, uncontrolled.
onPressedChange(pressed, details) => void—Called with the new state.
iconIconSource—An icon from @qeetrix/icons, drawn sharp, before the label.
filledWhenPressedbooleanfalseThe icon's filled drawing while pressed; for icons that have one.
aria-labelstring—Required with an icon alone: its name and its tooltip.
tooltipReactNode | falsearia-labelAn icon-only toggle's tooltip: other text, or false.
tooltipSide"top" | "bottom" | "left" | "right" | "inline-start" | "inline-end""top"The side it opens on; it flips when there's no room.
size"sm" | "md" | "lg""md"Height from the density tokens; a group's size wins.
valuestring—Its value inside a Toggle group.
disabledbooleanfalseIt can't be pressed.
childrenReactNode—The label.

03

Parts

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

data-slotElementWhat it is
toggle<button>The root. data-pressed while on; data-size; data-icon-only.
toggle-icon<svg>The icon, outline.
toggle-icon-filled<svg>The icon, filled: shown while pressed, with filledWhenPressed.

04

Controlled

pressed and onPressedChange, for a toggle the page reads from.

pin.tsx
const [pinned, setPinned] = useState(false);

<Toggle icon={PinIcon} filledWhenPressed pressed={pinned} onPressedChange={setPinned}>
  Pin to top
</Toggle>
Next — ToggleAccessibility