Tinyrack

ToggleGroup

Coordinates mutually exclusive or multiple toggle buttons. Like TRToggle, it does not submit a form value by itself.

Contract

AxisContract
selectionzero or one value by default; opt into independent values with multiple
statecontrolled value or uncontrolled defaultValue; both use string arrays and default to []
orientationhorizontal by default; vertical when requested
keyboardorientation-aware arrows plus Home/End; focus loops by default, or stops with loopFocus={false}
availabilityenabled by default; disable the group or an individual item

Install

pnpm add @tinyrack/ui

Scroll inside the code area to read long lines.

Styles

@import '@tinyrack/ui/components/toggle-group.css';

Scroll inside the code area to read long lines.

Imports

import { TRToggleGroup } from '@tinyrack/ui/components/toggle-group';
import { TRToggle } from '@tinyrack/ui/components/toggle';

Scroll inside the code area to read long lines.

Playground

Usage

Examples

API

Anatomy

<TRToggleGroup aria-label="Text alignment">
  <TRToggle value="start">Start</TRToggle>
  <TRToggle value="center">Center</TRToggle>
</TRToggleGroup>

TRToggleGroup is the state and roving-focus root. Its children are public TRToggle components imported from @tinyrack/ui/components/toggle; each grouped toggle needs a stable, unique value.

Props

PropTypeDefaultPurpose
valuereadonly string[]-Controlled pressed values.
defaultValuereadonly string[][]Initial uncontrolled pressed values.
onValueChange(value, details) => void-Reports the next array and native event details. Call details.cancel() to veto Base UI's internal update.
multiplebooleanfalseAllows each item to be toggled independently.
orientation'horizontal' | 'vertical''horizontal'Selects layout and the active arrow-key axis.
loopFocusbooleantrueWraps arrow-key focus at the first and last enabled items.
disabledbooleanfalseDisables every item in the group.
renderReactElement | function<div>Replaces the root while preserving behavior and merged refs/props.

The root renders with role="group", so provide aria-label or aria-labelledby. Left/Right move focus horizontally, Up/Down move it vertically, and Home/End move to the first/last enabled item. Disabled items are skipped during roving focus. Group disabled applies to every item, while an individual TRToggle can be disabled independently.

className, style, native div props, event handlers, and refs are forwarded. Customize spacing and text color with --tr-toggle-group-gap and --tr-toggle-group-color; toggle appearance remains available through the TRToggle tokens. Toggle groups do not submit a named form value, so use TRCheckboxGroup or TRRadioGroup when selection must participate in form submission.