Mediquo documentation home

Toggle

A button that stays on or off.

mq-toggle is web patient's Toggle as a design-system primitive. It ships from @mediquo/ui as a custom element and as a React component.

Install

// Custom element — the import registers <mq-toggle>
import "@mediquo/ui/components/toggle";
// React
import { Toggle } from "@mediquo/ui/react/toggle";

Variants and sizes

variant is default (no border) or outline. size is sm, md (the default) or lg. A pressed toggle takes the brand's light fill.

<Toggle
  variant="outline"
  pressed={bold}
  onPressedChange={(event) => setBold(event.pressed)}
>
  Negrita
</Toggle>

pressed flips on every click and onpressedchange reports it, so the toggle also works with pressed left unset.

Accessibility

  • It renders a native <button> with aria-pressed, so screen readers announce it as a toggle button and Enter and Space flip it.
  • An icon-only toggle needs a label. It becomes the button's accessible name, and the console warns when a toggle has neither text nor a label.
  • The label says what the toggle does, not its state: "Negrita", not "Activar negrita". aria-pressed already says whether it is on.
  • Forced-colours mode draws the border and marks the pressed state with the system highlight.

Styling

The component uses --mq-* tokens with literal fallbacks. --mq-toggle-radius sets the corners, --mq-toggle-pressed-background and --mq-toggle-pressed-color the pressed colours, and part="control" reaches the button.