# Toggle button

Turn one immediate view or mode on and off with a native pressed button.

Access: free. Category: Essentials. Kind: primitive.

## When to use

- Use it when a product interface needs turn one immediate view or mode on and off with a native pressed button.
- 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 button.

## 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 button

```sh
npx shadcn@latest add https://tidalui.com/r/toggle-button.json
```

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

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/toggle-button.css";
import{TidalToggleButton}from"./components/ui/toggle-button";
export default()=><div className="tidal-scope"><TidalToggleButton label={"Demo"}/></div>;
```

## Structured props

- `TidalToggleButton.label: ReactNode`: Required label value accepted by this exported component.
- `TidalToggleButton.defaultPressed?: boolean | undefined` (default false): Optional default pressed value accepted by this exported component.
- `TidalToggleButton.icon?: ReactNode`: Optional icon value accepted by this exported component.
- `TidalToggleButton.iconOnly?: boolean | undefined` (default false): Optional icon only value accepted by this exported component.
- `TidalToggleButton.onPressedChange?: ((pressed: boolean, event: MouseEvent<HTMLButtonElement>) => void) | undefined`: Callback invoked when the pressed change interaction is proposed.
- `TidalToggleButton.pressed?: boolean | undefined`: Optional pressed value accepted by this exported component.
- `TidalToggleButton.readOnly?: boolean | undefined` (default false): Optional read only value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/toggle-button.tsx) | [Manifest](https://tidalui.com/examples/toggle-button.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 { useState } from "react";

import { Bookmark, Rows3 } from "lucide-react";

import { TidalToggleButton } from "./components/ui/toggle-button";

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



const tidalExampleStyles = ".tidal-scope .toggle-button-demo {\n  display: flex;\n  width: min(100%, 420px);\n  min-width: 0;\n  margin-inline: auto;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  gap: 12px;\n}\n\n.tidal-scope .toggle-button-demo-actions {\n  display: flex;\n  min-width: 0;\n  flex-wrap: wrap;\n  align-items: center;\n  justify-content: center;\n  gap: 10px;\n}\n\n.tidal-scope .toggle-button-demo > p {\n  min-width: 0;\n  margin: 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.45;\n  text-align: center;\n  overflow-wrap: anywhere;\n}";

export function ToggleButtonDemo() {
  const [compact, setCompact] = useState(false);
  const [bookmarked, setBookmarked] = useState(true);

  return (
    <section className="toggle-button-demo" aria-label="Toggle button preview">
      <div
        className="toggle-button-demo-actions"
        role="group"
        aria-label="View options"
      >
        <TidalToggleButton
          label="Compact view"
          icon={<Rows3 size={18} aria-hidden="true" />}
          pressed={compact}
          onPressedChange={setCompact}
        />
        <TidalToggleButton
          label="Bookmark component"
          icon={<Bookmark size={18} aria-hidden="true" />}
          iconOnly
          pressed={bookmarked}
          onPressedChange={setBookmarked}
        />
      </div>
      <p role="status" aria-live="polite">
        {compact ? "Compact" : "Comfortable"} view ·{" "}
        {bookmarked ? "Bookmarked" : "Not bookmarked"}
      </p>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <ToggleButtonDemo />
    </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."],"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."}

Required ReactNode label supplies the default accessible name, remains available in iconOnly mode, and may be overridden by a native aria-label. Optional decorative icon, iconOnly, controlled pressed or uncontrolled defaultPressed, onPressedChange(nextPressed,event), and readOnly. Remaining compatible native button attributes, form ownership, name/value, submitter overrides, className, explicit aria-disabled=false and forwarded ref are preserved; type defaults to button but can be overridden. When available, native onClick runs first and preventDefault suppresses the state proposal; readOnly and disabled states suppress it. Native disabled and aria-disabled true resolve to disabled behavior; readOnly stays focusable, exposes aria-disabled and suppresses changes. Consumers own controlled acceptance, application behavior, persistence and form results.
