# Chat composer

Write messages with attachments, keyboard shortcuts and send or stop controls.

Access: pro. Category: Blocks. Kind: composite.

## When to use

- Use it when a page needs write messages with attachments, keyboard shortcuts and send or stop controls.
- Choose it inside an authenticated product surface when the host application owns routing, persistence, and service calls.

## Alternatives

- Choose empty-state instead when empty collections, search results and errors with a clear next action is the actual interface need, rather than chat composer.

## 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 Chat composer

```sh
npx shadcn@latest add @tidal-pro/chat-composer
```

Stylesheets: `components/ui/tidal.css`, `components/ui/chat-composer.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/chat-composer.css";
import{TidalChatComposer}from"./components/ui/chat-composer";
export default()=><div className="tidal-scope"><TidalChatComposer onSend={() => {}} onValueChange={() => {}} value={"value"}/></div>;
```

## Structured props

- `TidalChatComposer.onSend: (value: string, event: FormEvent<HTMLFormElement>) => void`: Callback invoked when the send interaction is proposed.
- `TidalChatComposer.onValueChange: (value: string, event: React.ChangeEvent<HTMLTextAreaElement>) => void`: Callback invoked when the value change interaction is proposed.
- `TidalChatComposer.value: string`: Required value value accepted by this exported component.
- `TidalChatComposer.attachmentTray?: TidalAttachmentTrayProps | undefined`: Optional attachment tray value accepted by this exported component.
- `TidalChatComposer.busy?: boolean | undefined` (default false): Optional busy value accepted by this exported component.
- `TidalChatComposer.canSend?: boolean | undefined` (default true): Optional can send value accepted by this exported component.
- `TidalChatComposer.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalChatComposer.error?: string | undefined`: Optional error value accepted by this exported component.
- `TidalChatComposer.label?: string | undefined` (default "Message"): Optional label value accepted by this exported component.
- `TidalChatComposer.labels?: { send?: string; stop?: string; sending?: string; } | undefined` (default {}): Optional labels value accepted by this exported component.
- `TidalChatComposer.onStop?: MouseEventHandler<HTMLButtonElement> | undefined`: Callback invoked when the stop interaction is proposed.
- `TidalChatComposer.placeholder?: string | undefined` (default "Write a message…"): Optional placeholder value accepted by this exported component.
- `TidalChatComposer.readOnly?: boolean | undefined` (default false): Optional read only value accepted by this exported component.
- `TidalChatComposer.submitButtonProps?: Omit<TidalButtonProps, "variant" | "loading" | "form" | "type" | "children"> | undefined` (default {}): Optional submit button props value accepted by this exported component.
- `TidalChatComposer.submitButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional submit button ref value accepted by this exported component.
- `TidalChatComposer.submitShortcut?: "none" | "enter" | "mod-enter" | undefined` (default "mod-enter"): Optional submit shortcut value accepted by this exported component.
- `TidalChatComposer.textareaProps?: TextareaProps | undefined` (default {}): Optional textarea props value accepted by this exported component.
- `TidalChatComposer.textareaRef?: Ref<HTMLTextAreaElement> | undefined`: Optional textarea ref value accepted by this exported component.
- `TidalChatComposer.tools?: ReactNode`: Optional tools value accepted by this exported component.

## Complete usage example

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

import { TidalChatComposer } from "./components/ui/chat-composer";

import type { TidalAttachment } from "./components/ui/attachment-tray";

import "./components/ui/attachment-tray.css";

import "./components/ui/chat-composer.css";

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

import "./components/ui/status-badge.css";

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



const tidalExampleStyles = ".tidal-scope .chat-composer-demo {\n  width: min(100%, 680px);\n  min-width: 0;\n}\n.tidal-scope .chat-composer-demo > p {\n  margin: 14px 2px 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.6;\n  overflow-wrap: anywhere;\n}\n.tidal-scope .composer-demo-attach {\n  min-height: 44px;\n  padding: 8px 12px;\n  border: 1px solid var(--t-border);\n  border-radius: 9px;\n  background: var(--t-surface);\n  color: var(--t-ink);\n  font: inherit;\n  font-size: 12px;\n}";

export function ChatComposerDemo() {
  const [value, setValue] = useState(
    "Summarize the release notes and list anything blocking launch.",
  );
  const [busy, setBusy] = useState(false);
  const [files, setFiles] = useState<TidalAttachment[]>([]);
  const [status, setStatus] = useState("Local sample. No message is sent.");
  const input = useRef<HTMLTextAreaElement>(null);
  return (
    <div className="chat-composer-demo">
      <TidalChatComposer
        value={value}
        onValueChange={setValue}
        busy={busy}
        textareaRef={input}
        onSend={(message) => {
          setBusy(true);
          setValue("");
          setStatus(
            `Sample received ${message.length} characters. Use Stop to end the preview.`,
          );
        }}
        onStop={() => {
          setBusy(false);
          setStatus("Sample response stopped. No request was made.");
        }}
        tools={
          <button
            type="button"
            className="composer-demo-attach"
            onClick={() => {
              setFiles([
                {
                  id: "notes",
                  name: "release-notes.md",
                  typeText: "Markdown",
                  sizeText: "4 KB",
                  status: "ready",
                },
              ]);
              setStatus("Sample attachment added locally.");
            }}
          >
            Attach sample
          </button>
        }
        attachmentTray={
          files.length
            ? {
                label: "Attachments",
                attachments: files,
                onRemove: (item, event) => {
                  if (document.activeElement === event.currentTarget)
                    input.current?.focus({ preventScroll: true });
                  setFiles(files.filter((file) => file.id !== item.id));
                  setStatus("Sample attachment removed.");
                },
              }
            : undefined
        }
      />
      <p role="status">{status}</p>
    </div>
  );
}

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

Controlled value/onValueChange, required onSend; native form submit is prevented. Optional busy/onStop, disabled/readOnly/canSend, label/placeholder/error, submitShortcut (mod-enter default, enter, none), textareaProps/ref, submitButtonProps/ref, tools, attachmentTray, labels and native form attributes/ref. Native handlers run before higher callbacks and can prevent them. Keyboard shortcuts ignore IME composition and Alt-modified input, use native requestSubmit and retain validation; Shift-Enter remains a newline. The one persistent button becomes Stop when busy and a stop callback exists, preserving focus. Busy without onStop exposes a disabled sending indicator. The attachment slot composes TidalAttachmentTray; disabled makes tools inert and owned attachment actions disabled. Consumers own message values, file state, sends/stops, requests and persistence.
