# Toggle group

Choose one or several compact modes with pressed buttons and roving keyboard focus.

Access: pro. Category: Essentials. Kind: primitive.

## When to use

- Use it when a product interface needs choose one or several compact modes with pressed buttons and roving keyboard focus.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose tidal-button instead when press, loading, success and disabled states is the actual interface need, rather than toggle group.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Toggle group

```sh
npx shadcn@latest add @tidal-pro/toggle-group
```

Stylesheets: `components/ui/tidal.css`, `components/ui/toggle-group.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/toggle-group.css";
import{TidalToggleGroup}from"./components/ui/toggle-group";
export default()=><div className="tidal-scope"><TidalToggleGroup label="View" items={[{ id: "list", value: "list", label: "List" }]} type="single" value="list" onValueChange={() => {}}/></div>;
```

## Structured props

- `TidalToggleGroup.items: ReadonlyArray<TidalToggleGroupItem>`: Required items value accepted by this exported component.
- `TidalToggleGroup.label: string`: Required label value accepted by this exported component.
- `TidalToggleGroup.onValueChange: ((value: string | null) => void) | ((value: string[]) => void)`: Callback invoked when the value change interaction is proposed.
- `TidalToggleGroup.type: "multiple" | "single"`: Required type value accepted by this exported component.
- `TidalToggleGroup.value: string | ReadonlyArray<string> | null`: Required value value accepted by this exported component.
- `TidalToggleGroup.dir?: "ltr" | "rtl" | undefined` (default "ltr"): Optional dir value accepted by this exported component.
- `TidalToggleGroup.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalToggleGroup.orientation?: "horizontal" | "vertical" | undefined` (default "horizontal"): Optional orientation value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/toggle-group.tsx) | [Manifest](https://tidalui.com/examples/toggle-group.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useId, useState } from "react";

import { AlignJustify, CalendarDays, CircleUserRound, Grid2X2, List, Tag } from "lucide-react";

import { TidalToggleGroup } from "./components/ui/toggle-group";

import "./components/ui/toggle-group.css";



const tidalExampleStyles = ".tidal-scope .toggle-group-demo,\n.tidal-scope .toggle-group-demo * {\n  box-sizing: border-box;\n}\n\n.tidal-scope .toggle-group-demo {\n  container: toggle-group-demo / inline-size;\n  display: grid;\n  gap: 16px;\n  width: min(100%, 620px);\n  min-width: 0;\n  color: var(--t-ink);\n}\n\n.tidal-scope .toggle-group-demo-controls {\n  display: grid;\n  grid-template-columns: minmax(280px, 0.95fr) minmax(0, 1.05fr);\n  gap: 16px;\n}\n\n.tidal-scope .toggle-group-demo-controls > div {\n  display: grid;\n  min-width: 0;\n  gap: 8px;\n}\n\n.tidal-scope .toggle-group-demo-controls > div > span {\n  color: var(--t-muted);\n  font-size: 11px;\n  font-weight: 650;\n  line-height: 1.4;\n}\n\n.tidal-scope .toggle-group-demo-controls .tidal-toggle-group {\n  width: 100%;\n}\n\n.tidal-scope .toggle-group-demo-controls .tidal-toggle-group-item {\n  min-width: 44px;\n  flex: 1 1 0;\n  gap: 5px;\n  padding-inline: 6px;\n}\n\n.tidal-scope .toggle-group-demo-projects {\n  display: block;\n  min-width: 0;\n}\n\n.tidal-scope .toggle-group-demo-projects article {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 10px;\n  min-width: 0;\n  min-height: 52px;\n  padding: 6px 10px;\n  border: 1px solid var(--t-border);\n  border-radius: 10px;\n  background: var(--t-surface);\n  transition:\n    border-radius 220ms var(--t-ease-out),\n    background 220ms var(--t-ease-out);\n}\n\n.tidal-scope .toggle-group-demo-projects[data-layout=\"grid\"] article {\n  border-radius: 14px;\n  background: var(--t-wash);\n}\n\n.tidal-scope .toggle-group-demo-projects[data-layout=\"dense\"] article {\n  min-height: 44px;\n  padding-block: 3px;\n}\n\n.tidal-scope .toggle-group-demo-project-name {\n  display: grid;\n  min-width: 0;\n}\n\n.tidal-scope .toggle-group-demo-project-name strong {\n  min-width: 0;\n  font-size: 13px;\n  line-height: 1.35;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .toggle-group-demo-project-name > span {\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.25;\n  text-transform: capitalize;\n}\n\n.tidal-scope .toggle-group-demo-project-meta {\n  display: flex;\n  flex-wrap: wrap;\n  justify-content: flex-end;\n  gap: 6px;\n  min-width: 0;\n}\n\n.tidal-scope .toggle-group-demo-project-meta span {\n  display: inline-flex;\n  min-height: 24px;\n  align-items: center;\n  padding-inline: 7px;\n  border: 1px solid var(--t-border);\n  border-radius: 6px;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.25;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .toggle-group-demo-note {\n  margin: 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.5;\n}\n\n@container toggle-group-demo (max-width: 520px) {\n  .tidal-scope .toggle-group-demo-controls {\n    grid-template-columns: minmax(0, 1fr);\n  }\n}\n\n@container toggle-group-demo (max-width: 300px) {\n  .tidal-scope .toggle-group-demo-projects article {\n    align-items: flex-start;\n    flex-direction: column;\n  }\n\n  .tidal-scope .toggle-group-demo-project-meta {\n    justify-content: flex-start;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .tidal-scope .toggle-group-demo-projects article {\n    transition: none;\n  }\n}";

export function ToggleGroupDemo() {
  const generatedId = useId().replace(/:/g, "");
  const [layout, setLayout] = useState<string | null>("grid");
  const [details, setDetails] = useState<string[]>(["owner", "status"]);

  return (
    <section
      className="toggle-group-demo"
      aria-labelledby={`${generatedId}-title`}
    >
      <div className="toggle-group-demo-controls">
        <div>
          <span id={`${generatedId}-title`}>Project view</span>
          <TidalToggleGroup
            type="single"
            label="Project layout"
            value={layout}
            onValueChange={setLayout}
            items={[
              {
                id: "grid",
                value: "grid",
                label: "Grid",
                icon: <Grid2X2 aria-hidden="true" />,
              },
              {
                id: "list",
                value: "list",
                label: "List",
                icon: <List aria-hidden="true" />,
              },
              {
                id: "dense",
                value: "dense",
                label: "Dense",
                icon: <AlignJustify aria-hidden="true" />,
              },
            ]}
          />
        </div>
        <div>
          <span>Visible details</span>
          <TidalToggleGroup
            type="multiple"
            label="Visible project details"
            value={details}
            onValueChange={setDetails}
            items={[
              {
                id: "owner",
                value: "owner",
                label: "Owner",
                icon: <CircleUserRound aria-hidden="true" />,
              },
              {
                id: "due",
                value: "due",
                label: "Due date",
                icon: <CalendarDays aria-hidden="true" />,
              },
              {
                id: "status",
                value: "status",
                label: "Status",
                icon: <Tag aria-hidden="true" />,
              },
            ]}
          />
        </div>
      </div>

      <div
        className="toggle-group-demo-projects"
        data-layout={layout ?? "plain"}
        aria-label="Sample project preview"
      >
        <article>
          <div className="toggle-group-demo-project-name">
            <strong>Launch notes</strong>
            <span>{layout ? `${layout} view` : "plain view"}</span>
          </div>
          <div className="toggle-group-demo-project-meta">
            {details.includes("owner") ? <span>Ava</span> : null}
            {details.includes("due") ? <span>Oct 18</span> : null}
            {details.includes("status") ? <span>Ready</span> : null}
          </div>
        </article>
      </div>
      <p className="toggle-group-demo-note">
        Sample project data. Changes stay in this preview.
      </p>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <ToggleGroupDemo />
    </div>
  );
}

```

## Gotchas

- Install the declared registry dependencies and render inside a tidal-scope with the foundation stylesheet loaded.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

A discriminated controlled API uses type='single' with string|null value or type='multiple' with a string array value. onValueChange proposes the next value without mutating consumer state. label names the form-free role=group. Items require unique IDs and values and support ReactNode labels, optional accessibleLabel for icon-only content, decorative icons, disabled state, native button attributes and individual refs. Buttons are always type=button, expose aria-pressed, and never serialize a form value. Caller click/keydown/focus handlers run first; prevention blocks activation or keyboard movement. One enabled item is tabbable; Home/End and orientation-aware arrow keys wrap while skipping disabled items, with Left/Right reversed in RTL. Horizontal groups scroll inline rather than clipping. Root props/ref, orientation, direction and disabled state are available. Consumers own state, validation, persistence and any focus movement after an accepted toggle.
