# Toggle Group

A coordinated single- or multiple-selection group of toggles with shared styling.

A coordinated single- or multiple-selection group of toggles. Each `ToggleGroup.Item` is a [`Toggle`](/components/toggle/) and inherits the same semantic surfaces, pressed colors, icon padding, and sizes from the group root unless overridden on the item.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/toggle-group">Base UI Toggle Group</a> for
  upstream behavior and configuration. Zenos owns the public API, styling, and composition shown on
  this page.
</p>

```tsx
import { Stack, ToggleGroup } from "@zentara-co/zenos-ui";

function ToggleGroupExample() {
  return (
    <Stack direction="row" justify="center" className="w-full">
      <ToggleGroup defaultValue={["left"]} variant="subtle" aria-label="Alignment">
        <ToggleGroup.Item value="left">Left</ToggleGroup.Item>
        <ToggleGroup.Item value="center">Center</ToggleGroup.Item>
        <ToggleGroup.Item value="right">Right</ToggleGroup.Item>
      </ToggleGroup>
    </Stack>
  );
}
```

```tsx
import { ToggleGroup } from "@zentara-co/zenos-ui";
```

## Composition

Use `ToggleGroup.Item` for each option and give the group an accessible name with `aria-label` or `aria-labelledby`. Text and icon children follow the same layout rules as standalone [`Toggle`](/components/toggle/) controls (automatic padding for text-only, leading icon, trailing icon, and icon-only layouts).

```tsx
import { ToggleGroup } from "@zentara-co/zenos-ui";

<ToggleGroup defaultValue={["list"]} variant="subtle" aria-label="View">
  <ToggleGroup.Item value="list">List</ToggleGroup.Item>
  <ToggleGroup.Item value="grid">Grid</ToggleGroup.Item>
</ToggleGroup>;
```

## Variants

Set `variant` on the group root so every item shares one surface treatment. Defaults match Toggle: `variant="subtle"` and `size="md"`.

| Variant          | Use                                                                                      |
| ---------------- | ---------------------------------------------------------------------------------------- |
| `subtle`         | Default filled neutral surface (recommended for most groups).                            |
| `subtle-outline` | Filled neutral surface with a border; the previous `outline` appearance.                 |
| `outline`        | Transparent surface; selected border, translucent fill, and semibold label when pressed. |
| `default`        | Transparent until hover; lightweight toolbar groups.                                     |

```tsx
import { Stack, ToggleGroup } from "@zentara-co/zenos-ui";

function ToggleGroupVariantsExample() {
  return (
    <Stack gap="4" align="center" className="w-full">
      {(["subtle", "subtle-outline", "outline", "default"] as const).map((variant) => (
        <ToggleGroup
          key={variant}
          variant={variant}
          defaultValue={["list"]}
          aria-label={`${variant} view`}
        >
          <ToggleGroup.Item value="list">List</ToggleGroup.Item>
          <ToggleGroup.Item value="grid">Grid</ToggleGroup.Item>
          <ToggleGroup.Item value="board">Board</ToggleGroup.Item>
        </ToggleGroup>
      ))}
    </Stack>
  );
}
```

## Single and multiple selection

Single selection is the default and stores its selected item in a string array. Add `multiple` when choices may be combined. Use controlled `value` and `onValueChange` when the application owns selection.

```tsx
import { TextBIcon, TextItalicIcon } from "@phosphor-icons/react";
import { Stack, Text, ToggleGroup } from "@zentara-co/zenos-ui";
import { useState } from "react";

function ToggleGroupMultipleExample() {
  const [value, setValue] = useState(["bold", "italic"]);

  return (
    <Stack gap="3" align="center" className="w-full">
      <ToggleGroup
        multiple
        value={value}
        onValueChange={setValue}
        variant="subtle"
        aria-label="Text formatting"
      >
        <ToggleGroup.Item value="bold" aria-label="Bold">
          <TextBIcon aria-hidden />
        </ToggleGroup.Item>
        <ToggleGroup.Item value="italic" aria-label="Italic">
          <TextItalicIcon aria-hidden />
        </ToggleGroup.Item>
        <ToggleGroup.Item value="disabled" disabled>
          Locked
        </ToggleGroup.Item>
      </ToggleGroup>
      <Text size="s" color="subtle" aria-live="polite">
        Active formatting: {value.length ? value.join(", ") : "None"}
      </Text>
    </Stack>
  );
}
```

## Visual states

Pressed `outline` items use a selected border, translucent selected cover, selected text, and a semibold label in both themes. Other variants retain the accent red subtlest pressed fill. Disabled items use muted text; a disabled pressed item keeps a faint red surface and accent red label so the prior selection stays visible but not editable.

To preserve the previous filled, bordered appearance, change the group root to `variant="subtle-outline"`. Individual items can override the inherited variant.

## Orientation

Vertical groups stack items and change roving-focus navigation to Up and Down Arrow.

```tsx
import { Stack, ToggleGroup } from "@zentara-co/zenos-ui";

function ToggleGroupVerticalExample() {
  return (
    <Stack direction="row" justify="center" className="w-full">
      <ToggleGroup
        orientation="vertical"
        variant="subtle"
        size="sm"
        defaultValue={["overview"]}
        aria-label="Workspace view"
      >
        <ToggleGroup.Item value="overview">Overview</ToggleGroup.Item>
        <ToggleGroup.Item value="activity">Activity</ToggleGroup.Item>
        <ToggleGroup.Item value="settings">Settings</ToggleGroup.Item>
      </ToggleGroup>
    </Stack>
  );
}
```

## Custom styling

Pass `className` to `ToggleGroup` to customize its layout, gap, container surface, and border. Style every item from the root with the `[data-slot=toggle-group-item]` selector, or pass `className` to an individual `ToggleGroup.Item` when only one option needs a different treatment.

Items expose `data-pressed` for the selected state. Prefer semantic tokens for custom surfaces and foregrounds, and keep visible hover and focus feedback intact. Selection behavior, roving focus, orientation, and inherited `size` remain unchanged.

```tsx
import { ToggleGroup } from "@zentara-co/zenos-ui";

function ToggleGroupCustomExample() {
  return (
    <ToggleGroup
      defaultValue={["grid"]}
      aria-label="Results layout"
      className="gap-0 rounded-lg border border-border-default bg-background-neutral-card p-1 [&_[data-slot=toggle-group-item]]:rounded-sm [&_[data-slot=toggle-group-item]]:bg-transparent [&_[data-slot=toggle-group-item]]:text-text-subtle [&_[data-slot=toggle-group-item]]:hover:bg-background-accent-teal-subtlest-hover [&_[data-slot=toggle-group-item][data-pressed]]:bg-background-accent-teal-subtlest-pressed [&_[data-slot=toggle-group-item][data-pressed]]:text-text-accent-teal-bolder"
    >
      <ToggleGroup.Item value="list">List</ToggleGroup.Item>
      <ToggleGroup.Item value="grid">Grid</ToggleGroup.Item>
      <ToggleGroup.Item value="board">Board</ToggleGroup.Item>
    </ToggleGroup>
  );
}
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| variant | 'default' \| 'outline' \| 'subtle' \| 'subtle-outline' | subtle | Surface treatment inherited by items. |
| size | 'sm' \| 'md' \| 'lg' | md | Control height inherited by items. |
| multiple | boolean | false | Allows more than one pressed item. |
| orientation | 'horizontal' \| 'vertical' | horizontal | Layout and arrow-key navigation direction. |
| value / defaultValue | string[] | — | Controlled or initial selected item values. |
| onValueChange | (value: string[], eventDetails) => void | — | Runs when selection changes. |

## Sizes

sm, md, lg

## Anatomy

```text
ToggleGroup.Root
ToggleGroup.Item
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| value | string[] | — | Controlled selected values. |
| defaultValue | string[] | — | Initial uncontrolled values. |
| onValueChange | (value: string[], eventDetails) => void | — | Runs when selection changes. |
| multiple | boolean | false | Allows more than one pressed item. |
| variant | default \| outline \| subtle \| subtle-outline | subtle | Surface treatment inherited by items (same semantics as Toggle). |
| size | sm \| md \| lg | md | Control height inherited by items. |
| orientation | horizontal \| vertical | horizontal | Layout and roving-focus direction. |
| disabled | boolean | false | Disables every item in the group. |
| native props | React.Base UI ToggleGroup props | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Give every group a name with `aria-label` or `aria-labelledby`, and label icon-only items individually. Arrow keys move focus according to orientation while Space or Enter changes the focused item. Disabled items are skipped. Use single selection for mutually exclusive views and multiple selection only when simultaneous pressed states make sense.

## Related

See [`Toggle`](/components/toggle/) for standalone two-state controls and per-item `pressed` / `onPressedChange` when selection is not shared.

Source: https://zenos-ui.pages.dev/components/toggle-group/