# Toggle switch

Labeled switches for settings and preferences.

Access: pro. Category: Forms. Kind: primitive.

## When to use

- Use it when a product interface needs labeled switches for settings and preferences.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than toggle switch.

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

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

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

## Minimal example

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

## Structured props

- `TidalSwitch.checked: boolean`: Required checked value accepted by this exported component.
- `TidalSwitch.label: string`: Required label value accepted by this exported component.
- `TidalSwitch.onCheckedChange: (checked: boolean) => void`: Callback invoked when the checked change interaction is proposed.
- `TidalSwitch.description?: string | undefined`: Optional description value accepted by this exported component.
- `TidalSwitch.rootClassName?: string | undefined` (default ""): Optional root class name value accepted by this exported component.

## Complete usage example

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

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

import { TidalSwitch } from "./components/ui/toggle-switch";

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

import { useState } from "react";



const tidalExampleStyles = ".switch-specimen{width:100%;max-width:370px;padding:26px;background:var(--t-surface);border:1px solid var(--t-border);border-radius:var(--t-radius-card);box-shadow:0 12px 24px -14px #00000026,0 1px 2px #00000008}.switch-specimen>.demo-eyebrow{font-size:11px}.switch-specimen>h3{font-size:23px;letter-spacing:-.8px;margin:12px 0 9px;color:var(--t-ink)}.switch-specimen>p{font-size:11px;color:var(--t-muted);line-height:1.6}.switch-demo-rows{margin-top:22px}.switch-demo-rows>.tidal-switch{padding:14px 0;border-top:1px solid var(--t-border)}.switch-specimen>.switch-demo-status{font-size:11px;margin-bottom:0}";

export function SwitchDemo() {
  const [email, setEmail] = useState(true);
  const [digest, setDigest] = useState(false);
  return (
    <div className="switch-specimen">
      <div className="switch-demo-rows">
        <TidalSwitch
          label="Project updates"
          description="Receive project activity by email."
          checked={email}
          onCheckedChange={setEmail}
          name="projectUpdates"
        />
        <TidalSwitch
          label="Weekly digest"
          description="Receive a weekly activity summary."
          checked={digest}
          onCheckedChange={setDigest}
          name="weeklyDigest"
        />
        <TidalSwitch
          label="Security notices"
          description="Required security alerts."
          checked={true}
          onCheckedChange={() => {}}
          disabled
        />
      </div>
      <p className="switch-demo-status" role="status">
        {email ? "Project updates on" : "Project updates off"} ·{" "}
        {digest ? "Digest on" : "Digest off"}
      </p>
    </div>
  );
}

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

```

## Gotchas

- The host application owns data, validation, persistence, navigation, and service side effects described by this API.

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

{"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."}

Controlled checked and onCheckedChange; label required. Optional description, rootClassName and native checkbox input props/ref (name, value, required, disabled, id, className, aria-describedby). Visible label and linked help; switch semantics, native Space and form participation. The consumer owns persistence.
