<!-- index: /slotted/llms.txt -->
# toggle-group

`data-ui="toggle-group"` · Set of toggles, single or multiple.

## Import

```tsx
import { ToggleGroup, ToggleGroupDefaultsProvider, ToggleGroupItem } from '@slotted/react';
```

## Minimal example

Example

```tsx
import { ToggleGroup, ToggleGroupItem } from '@slotted/react/toggle-group';

export default function ToggleGroupBasic() {
  return (
    <ToggleGroup aria-label="Revenue period" defaultValue={['week']}>
      <ToggleGroupItem value="day">Day</ToggleGroupItem>
      <ToggleGroupItem value="week">Week</ToggleGroupItem>
      <ToggleGroupItem value="month">Month</ToggleGroupItem>
      <ToggleGroupItem value="quarter">Quarter</ToggleGroupItem>
    </ToggleGroup>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div, or the element render returns | yes |
| `item` | button, or the element ToggleGroupItem’s render returns | yes |
| `icon` | span | no |
| `label` | span | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `value` | `readonly string[]` | — | ToggleGroup | Present means the consumer owns the set, for the life of the component. Absent, the group owns it and starts from defaultValue |
| `defaultValue` | `readonly string[]` | — | ToggleGroup | What an uncontrolled group starts from, read once. A later change to it does not silently become new state |
| `multiple` | `boolean` | false | ToggleGroup | Whether more than one item may be on at a time. The value stays an array either way, so both bindings hold one shape and a single-select consumer writes an array of one |
| `deselectable` | `boolean` | true | ToggleGroup | Whether the last item on may be turned off. Ignored while multiple is true, where a set may always empty |
| `size` | `'sm' \| 'md' \| 'lg'` | md | ToggleGroup | The control step the bar and every item sit at. It reads the control scale, so the bar is as tall as the field beside it |
| `variant` | `'outline' \| 'ghost' \| 'chips'` | outline | ToggleGroup | Whether the bar draws its own edge, or draws its items as chips: separate rounded items that wrap, never joined, the pressed one in the neutral tone ink. There is no tone axis: “on” is one color across the system, and a bar that wants the whole palette is button-group around ToggleButtons |
| `orientation` | `'horizontal' \| 'vertical'` | horizontal | ToggleGroup | How the items flow, and which pair of arrows moves focus. A vertical group writes aria-orientation |
| `attached` | `boolean` | true | ToggleGroup | Whether the items are joined into one bar or spaced apart. A joined bar overlaps its items by one border so a shared column holds one line |
| `fullWidth` | `boolean` | false | ToggleGroup | Whether the items share the whole line. Left alone the bar is as wide as its labels |
| `loop` | `boolean` | true | ToggleGroup | Whether the arrows wrap past the ends of the set |
| `rovingFocus` | `boolean` | inferred | ToggleGroup | Whether the group holds a tab stop of its own. Unstated it is inferred: a group inside a toolbar stands down, because a bar is already one stop with arrow navigation across every control it holds |
| `disabled` | `boolean` | false | ToggleGroup | Unstated rather than false, so an item may state its own. Stated, it reaches every item as the native attribute, which is also what makes the browser skip it with the arrows |
| `value, on ToggleGroupItem` | `string` | — | ToggleGroupItem | What this item turns on, and what the group’s value holds. It is required: an item with no value is a control that changes nothing |
| `icon, on ToggleGroupItem` | `ReactNode` | — | ToggleGroupItem | The mark drawn before the words, sized from the control glyph scale and hidden from the reading order |
| `disabled, on ToggleGroupItem` | `boolean` | — | ToggleGroupItem | One item out of action while the rest of the bar stays live. An item that is on and unavailable keeps saying both |
| `render` | `(props: ToggleGroupRootProps \| ToggleGroupItemRootProps) => ReactNode` | — | ToggleGroup, ToggleGroupItem | Substitutes either root and hands it every attribute the family was going to write, including the ref the group needs for its own ring |
| `ref` | `Ref<HTMLDivElement> \| Ref<HTMLButtonElement>` | — | ToggleGroup, ToggleGroupItem | Reaches the element. focus() and click() are the element’s own, so no imperative handle is invented for what the platform already ships |
| `useToggleGroup()` | `() => ToggleGroupContextValue` | — | inside a ToggleGroup | What an item reads to know whether it is on and how to ask for a change. It throws outside a group rather than rendering a button that toggles nothing |
| `ToggleGroupDefaultsProvider` | `{ attached, deselectable, loop, orientation, size, variant }` | — | a subtree | The six decisions an application takes once. A group that states any of them itself still wins |
| `role` | `string` | group | ToggleGroup | A consumer’s own wins. The family writes group and never toolbar: toolbar is a keyboard model, and it is the toolbar family |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onValueChange` | `(value: readonly string[], request: ChangeRequest<readonly string[]>)` | Before the value moves. The request carries the new array, the array it replaces, the reason — pointer or keyboard — the originating event, and cancel(), which refuses the move before anything commits. Nothing is emitted for a value equal to the one the group already holds. |
| `onClick, onFocus, onBlur, on each item` | `the element’s own events` | Whenever that item’s button fires them. ToggleGroupItem composes with the application’s handler rather than replacing it: the application’s runs first, and always runs. Calling preventDefault() in onClick stops the toggle as well. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `size` | `sm`, `md`, `lg` | `md` |
| `variant` | `outline`, `ghost`, `chips` | `outline` |
| `orientation` | `horizontal`, `vertical` | `horizontal` |

## Rules

- There is no APG pattern called “toggle group”. The container is a group, each item is the Button pattern’s toggle button (w3.org/WAI/ARIA/apg/patterns/button/), and the movement between them is the Toolbar pattern’s roving tabindex (w3.org/WAI/ARIA/apg/patterns/toolbar/). Citing one and implying the other is how a family ends up with half a keyboard.
- So the arrows move focus and never toggle, which is the one place toggle group and segmented-control genuinely differ and the one a reader feels. Space and Enter turn the focused item on or off; Home and End reach the ends; a horizontal group ignores the cross axis so the page keeps scrolling with focus inside it.
- aria-pressed is written in both states, so an item is announced as a toggle rather than as a button that happens to be pressed — and the label never changes with the state, which the Button pattern calls critical. An item with only a mark takes its name from an aria-label the consumer writes.
- Inside a toolbar the group gives its keyboard up: a bar is already one tab stop with arrow navigation across every control it holds. The bar is found in the DOM by its public identifier rather than through an imported context, so neither depends on the other; rovingFocus states it outright for a bar this library did not write.
- disabled is the native attribute, because that is also what makes the browser refuse focus and what makes the ring skip the item. The group is not a form control: a set of choices a form submits is checkbox-group for many and segmented-control for one.
- The target is the item itself, never narrower than it is tall, so the WCAG 2.2 minimum of 24 by 24 holds at the smallest step and the tightest density — and the theme grows every control to 44 under a coarse pointer.

## Tokens

`--slotted-control-border-color`, `--slotted-control-border-width`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-font-weight`, `--slotted-control-gap-lg`, `--slotted-control-gap-md`, `--slotted-control-gap-sm`, `--slotted-control-height-lg`, `--slotted-control-height-md`, `--slotted-control-height-sm`, `--slotted-control-icon-size-lg`, `--slotted-control-icon-size-md`, `--slotted-control-icon-size-sm`, `--slotted-control-letter-spacing`, `--slotted-control-line-height`, `--slotted-control-padding-inline-lg`, `--slotted-control-padding-inline-md`, `--slotted-control-padding-inline-sm`, `--slotted-control-radius`, `--slotted-control-shadow`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-duration-instant`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-weight-medium`, `--slotted-radius-full`, `--slotted-space-3`, `--slotted-text`, `--slotted-toggle-group-active-background`, `--slotted-toggle-group-border-color`, `--slotted-toggle-group-chips-gap`, `--slotted-toggle-group-chips-pressed-background`, `--slotted-toggle-group-chips-pressed-color`, `--slotted-toggle-group-chips-radius`, `--slotted-toggle-group-color`, `--slotted-toggle-group-disabled-border-color`, `--slotted-toggle-group-disabled-color`, `--slotted-toggle-group-disabled-pressed-background`, `--slotted-toggle-group-hover-background`, `--slotted-toggle-group-pressed-background`, `--slotted-toggle-group-pressed-border-color`, `--slotted-toggle-group-pressed-color`, `--slotted-toggle-group-pressed-hover-background`, `--slotted-toggle-group-radius`, `--slotted-toggle-group-shadow`, `--slotted-tone-accent-border`, `--slotted-tone-accent-subtle-active`, `--slotted-tone-accent-subtle-hover`, `--slotted-tone-accent-text`, `--slotted-tone-neutral-on-solid`, `--slotted-tone-neutral-solid`, `--slotted-tone-neutral-solid-hover`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`

## Examples

See [toggle-group.examples.md](./toggle-group.examples.md).
