Toggle Group
Compound toggle button group with keyboard navigation for single or multiple selection.
Installation
dgadd is not public on npm yet. Until the first release, pack @diffgazer/add from the repository and install that tarball into this app, which is what puts dgadd on pnpm exec.
The hosted registry is not public yet because r.b4r7.dev does not resolve. Use this source checkout or a local registry preview until the endpoint returns 200.
Diffgazer packages are not yet published to npm. Until the first release, pack @diffgazer/ui and @diffgazer/keys from the repository and install those tarballs.
UI components require Tailwind CSS v4. Local copy mode imports src/styles/styles.css; package mode uses @diffgazer/ui CSS once packages are available.
Usage
Examples
Variants
With Counts
Multiple Selection
Sizes
Vertical
Disabled
API Reference
ToggleGroup
ToggleGroup.Item
Data attributes
Accessibility
Keyboard Navigation
Arrow keys move focus between toggle items with wrapping. Single mode follows focus; multiple mode and allow-deselect single mode use button semantics and toggle with Enter or Space.
| Key | Action |
|---|---|
| ArrowRight / ArrowDown | Moves focus to the next enabled item; wraps when wrap is true. |
| ArrowLeft / ArrowUp | Moves focus to the previous enabled item; wraps when wrap is true. |
| Home / End | Moves focus to the first or last enabled item. |
| Enter / Space | Toggles the focused item in multiple mode or allow-deselect single mode; native radio-style single mode changes selection during arrow navigation. |
With keyboard navigation
Notes
Requires @diffgazer/keys (package mode)
ToggleGroup's arrow-key navigation imports from the required @diffgazer/keys peer. Package consumers must install @diffgazer/keys with @diffgazer/ui; packages are not yet published to npm, so until the first release install both from locally packed tarballs. Importing @diffgazer/ui/components/toggle-group without keys fails at module load with an error naming the missing @diffgazer/keys package. Copy/dgadd consumers do not need the package — copy mode rewrites the keyboard hooks to local source.
Compound Component
ToggleGroup uses compound sub-components (ToggleGroup.Item) rather than a data array. Each item accepts children for the label and an optional count prop that renders as [label count].
Composition Contract
Use ToggleGroup.Item as an explicit child in the ToggleGroup JSX tree. Custom item UI belongs inside ToggleGroup.Item. Components that create items internally from an opaque wrapper are not part of the current public contract.
Keyboard Navigation
Arrow keys move roving focus with wrapping by default. In single mode, selection follows focus unless allowDeselect is enabled; in multiple mode, arrow keys move focus and Enter/Space toggles the focused item. Highlight state can be controlled externally via highlighted and onHighlightChange props. Use onNavigationBoundaryReached for composite focus handoff when wrap is false.
Role semantics
Single mode without allowDeselect renders as radiogroup/radio with aria-checked and allows at most one active choice. Initial selection is optional: defaultValue=null starts with no radio checked. Multiple mode and allow-deselect single mode render as group plus button-style items with aria-pressed because each item is independently toggleable.
Source
Install via CLI: pnpm exec dgadd add ui/toggle-group. Keyboard hooks are included as standalone copies. For the full experience, use --integration keys.
Highlighted source loads after this disclosure opens. Browse the source repository.