Rime

ToggleGroup

A set of toggles sharing one value: single (a clearable radio set) or multiple.

ToggleGroup sits its items on one recessed track and lifts the pressed ones out as solid keys. type="single" allows at most one pressed item, and pressing it again clears the value; type="multiple" allows any number.

It has one tab stop: arrow keys move between items and Space or Enter presses. For a view switch where one option is always chosen, SegmentedControl reads better.

Usage

import { ToggleGroup } from "@/components/ui";

<ToggleGroup
  type="single"
  aria-label="Text alignment"
  value={align}
  onValueChange={setAlign}
  items={[
    { value: "left", icon: <AlignLeft size={16} />, "aria-label": "Align left" },
    { value: "center", icon: <AlignCenter size={16} />, "aria-label": "Align centre" },
  ]}
/>

Examples

Single and multiple

Text items

API

Generated from the component's TypeScript types and JSDoc (scripts/gen-ui-registry.mjs), so it always matches the source.

ToggleGroup

ToggleGroup props
PropTypeDefaultDescription
itemsRequiredReadonlyArray<ToggleGroupItem>
aria-labelRequiredstringNames the group: "Text formatting", "Days".
variant"ghost" | "outline" | "ghost" | "outline""outline"
size"sm" | "md" | "sm" | "md""md"
orientation"horizontal" | "vertical" | "horizontal" | "vertical""horizontal"
disabledboolean
classNamestring
typeRequired"single" | "multiple"single: at most one item pressed, like a radio group that can be cleared.
valueRequiredstring | null | ReadonlyArray<string>
onValueChangeRequired(value: string | null) => void | (value: string[]) => void

Theme tokens

Per-component tokens are undeclared by default, so the default shown is the fallback the CSS uses. Set one at :root (or in theme.css) to restyle every instance. Live values are read from this page, so they follow the Rime Studio.

ToggleGroup per-component tokens
TokenDefaultLive value
--toggle-height-mdvar(--control-h-md)…
--toggle-height-smvar(--control-h-sm)…
--toggle-inkvar(--ink-muted)…
--toggle-on-bgvar(--wash-active) / var(--surface-solid)…
--toggle-on-inkvar(--ink-brand)…
--toggle-on-linevar(--line-brand-strong)…
--toggle-radiusvar(--r-md) / var(--r-sm)…

System tokens it reads

ToggleGroup system tokens
TokenDefaultLive value
--border-wtokens.css…
--control-h-mdtokens.css…
--control-h-smtokens.css…
--densitytokens.css…
--durtokens.css…
--easetokens.css…
--focus-ringtokens.css…
--font-bodytokens.css…
--ink-brandtokens.css…
--ink-disabledtokens.css…
--ink-headingtokens.css…
--ink-mutedtokens.css…
--linetokens.css…
--line-brand-strongtokens.css…
--line-inputtokens.css…
--r-mdtokens.css…
--r-smtokens.css…
--recess-filltokens.css…
--rgb-whitetokens.css…
--shadow-hairline-cardtokens.css…
--shadow-recesstokens.css…
--surface-solidtokens.css…
--text-smalltokens.css…
--wash-activetokens.css…
--wash-hovertokens.css…

Accessibility

  • single renders role="radiogroup" with role="radio" items and aria-checked; multiple renders role="group" with aria-pressed buttons.
  • Roving tabindex: one tab stop, arrows move (Up and Down when vertical), Home and End jump to the ends.
  • aria-label on the group is required; icon-only items each need their own aria-label.

Do and don't

Do

  • Use multiple for independent options (bold, italic).
  • Keep items to one short word or a familiar icon.

Don't

  • Don't use single where a value is always required; use SegmentedControl.

For AI agents

This page as markdown, rendered from the same registry entry. Point an agent at it (or add .md to this page's URL), or at /llms.txt for the index.

Open toggle-group.md

Related: toggle, tabs, button-group