Toggle Group

A set of two-state buttons that can be toggled on or off, with support for single or multiple selection.

Overview

The ToggleGroup component manages a collection of toggle buttons that can work independently or together. Built on Base UI primitives, it supports multiple selection modes, variants (including an animated segmented control style), and customizable sizes.

Usage

import { ToggleGroup, ToggleGroupItem } from "@tilt-legal/cubitt-components/primitives";
<ToggleGroup multiple={true} defaultValue={["bold"]}>
  <ToggleGroupItem value="bold" aria-label="Toggle bold">
    <TextBold />
  </ToggleGroupItem>
  <ToggleGroupItem value="italic" aria-label="Toggle italic">
    <TextItalic />
  </ToggleGroupItem>
</ToggleGroup>

Examples

Segmented Variant

Toggle group with animated sliding indicator for single selection.

Segmented Sizes

Segmented toggle groups in different sizes with animated indicator.

Segmented With Separator

Use ToggleGroupSeparator inside the segmented track to split related options. The separator fades out whenever the active pill touches it, then becomes visible again once selection moves away.

Outline Variant

Toggle group with outlined buttons.

Outline Sizes

Toggle groups in different sizes.

URL State

Sync toggle group selection with the URL. Try selecting a value and refreshing the page.

Polymorphic Rendering

Render segmented toggle items through a custom link component while preserving pressed state.

API Reference

ToggleGroup

The root container component that manages the toggle button group.

PropTypeDefaultDescription
valuestring | string[]The controlled value(s) of the pressed item(s). String for single, array for multiple.
defaultValuestring | string[]The default value(s) when uncontrolled.
onValueChange(value: string | string[]) => voidCallback fired when the value changes. Returns string for single, array for multiple.
multiplebooleanWhen true, multiple items can be pressed. When false, only one. Auto-detected from value type if not specified.
groupVariant"default" | "outline" | "segmented""default"Visual style variant. Segmented shows animated indicator for single selection.
variant"default" | "outline""default"Toggle button variant (passed to items).
size"sm" | "md" | "lg""md"Size of the toggle buttons.
disabledbooleanfalseWhether all toggle buttons are disabled.
loopbooleantrueWhether keyboard focus loops back to the first item.
orientation"horizontal" | "vertical""horizontal"Layout orientation of the toggle group.
classNamestringAdditional CSS classes for the toggle group container.

URL State Props

When provided with a paramName, the toggle group will sync its selection with URL parameters via TanStack Router search params.

PropTypeDefaultDescription
paramNamestringURL parameter name for syncing state with URL. Enables URL state management.
onUrlValueChange(value: string | string[] | null) => voidCallback when URL parameter value changes.
paramClearOnDefaultbooleantrueRemove URL param when value equals default.
paramThrottlenumberThrottle URL updates in milliseconds.
paramDebouncenumberDebounce URL updates in milliseconds.

ToggleGroupItem

Individual toggle button within a ToggleGroup.

PropTypeDefaultDescription
valuestringUnique value for this toggle button (required).
mode"icon"Square sizing for icon-only content. Renders as a circle in segmented variant.
disabledbooleanfalseWhether this specific toggle button is disabled.
variant"default" | "outline"Override the group's variant for this item.
size"sm" | "md" | "lg"Override the group's size for this item.
renderReactElement | functionRender the item as a custom element or component while preserving toggle state.
nativeButtonbooleantrueSet to false when render outputs a non-button element like Link or a.
classNamestringAdditional CSS classes for the toggle button.
childrenReact.ReactNodeContent of the toggle button (icons, text, etc.).

Notes

  • Selection modes: Set multiple={true} for multi-select or multiple={false} for single-select. If omitted, auto-detects from value type (array = multiple, string = single)
  • Multiple selection (multiple={true}): Users can toggle multiple items on/off independently
  • Single selection (multiple={false}): Only one item can be selected at a time
  • The segmented variant with single selection (multiple={false}) provides an animated sliding indicator
  • onValueChange returns the appropriate format: string for single selection, array for multiple selection
  • For icon-only buttons, always provide aria-label for accessibility
  • The component uses Motion for animations in segmented variant, respecting prefers-reduced-motion

On this page