Skip to content
Agent UI
PrimitivesSwitch

Switch

Native checkbox with switch semantics and focus styles. Import from @agent-ui/react or a direct subpath. Tailwind CSS v4 theme tokens are required.

Switch ships with a full API table, a copyable example, and accessibility notes.

tsx

Installation

Install the package once, then import Switch from its direct entry point or from the root.

bash
pnpm add @agent-ui/react
tsx
import { Switch } from "@agent-ui/react/switch";

Tailwind CSS v4 users: add @source "../node_modules/@agent-ui/react/src" to the global stylesheet so the library utilities are generated.

Usage

The example below is the same code that renders the preview. Copy it, swap in your own handlers, and ship.

tsx
import { Switch } from "@agent-ui/react";
 
<label><Switch defaultChecked /> Stream responses</label>

API reference

Every prop Switch accepts, its type, default, and behaviour.

API reference for this component
NameTypeDefaultDescription
checkedboolean—Configuration exposed through the component's public React props.
defaultCheckedboolean—Configuration exposed through the component's public React props.
onChange(next: unknown) => void—Controlled state change callback.
disabledboolean—Configuration exposed through the component's public React props.

Accessibility

Uses native HTML semantics, keyboard controls and visible focus styles where applicable.
Use it with the rest of the library

Switch composes with MessageList, ChatShell, useChat, and the provider compose blocks. Browse the full reference or see all components in the gallery.

3 lines · copy-ready