# Attachment tray

Review queued files, progress and errors before sending a message.

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

## When to use

- Use it when a page needs review queued files, progress and errors before sending a message.
- 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 attachment tray.

## 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 Attachment tray

```sh
npx shadcn@latest add @tidal-pro/attachment-tray
```

Stylesheets: `components/ui/tidal.css`, `components/ui/attachment-tray.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/attachment-tray.css";
import{TidalAttachmentTray}from"./components/ui/attachment-tray";
export default()=><div className="tidal-scope"><TidalAttachmentTray attachments={[{id:"example",name:"Demo",status:"error"}]} label={"Demo"}/></div>;
```

## Structured props

- `TidalAttachmentTray.attachments: ReadonlyArray<TidalAttachment>`: Required attachments value accepted by this exported component.
- `TidalAttachmentTray.label: string`: Required label value accepted by this exported component.
- `TidalAttachmentTray.actions?: ReactNode`: Optional actions value accepted by this exported component.
- `TidalAttachmentTray.aria-disabled?: Booleanish | undefined`: Accessible disabled supplied by the consumer.
- `TidalAttachmentTray.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalAttachmentTray.emptyMessage?: ReactNode` (default "No attachments."): Optional empty message value accepted by this exported component.
- `TidalAttachmentTray.headingLevel?: 2 | 3 | 4 | 5 | 6 | undefined` (default 3): Optional heading level value accepted by this exported component.
- `TidalAttachmentTray.onRemove?: ((attachment: TidalAttachment, event: MouseEvent<HTMLButtonElement>) => void) | undefined`: Callback invoked when the remove interaction is proposed.
- `TidalAttachmentTray.onRetry?: ((attachment: TidalAttachment, event: MouseEvent<HTMLButtonElement>) => void) | undefined`: Callback invoked when the retry interaction is proposed.

## Complete usage example

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

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

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

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

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



const tidalExampleStyles = ".tidal-scope .attachment-tray-demo {\n  width: min(100%, 640px);\n  min-width: 0;\n}\n.tidal-scope .attachment-demo-advance,\n.tidal-scope .attachment-demo-footer > button {\n  min-height: 44px;\n  padding: 8px 12px;\n  border: 1px solid var(--t-border);\n  background: var(--t-surface);\n  border-radius: 9px;\n  color: var(--t-ink);\n  font: inherit;\n  font-size: 12px;\n  cursor: pointer;\n}\n.tidal-scope .attachment-demo-advance:disabled {\n  opacity: 0.45;\n  cursor: not-allowed;\n}\n.tidal-scope .attachment-demo-footer {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 12px;\n  align-items: center;\n  justify-content: space-between;\n  margin-top: 16px;\n}\n.tidal-scope .attachment-demo-footer > p {\n  flex: 1 1 200px;\n  min-width: 0;\n  margin: 0;\n  font-size: 11px;\n  line-height: 1.6;\n  color: var(--t-muted);\n}";

const sample: TidalAttachment[] = [
  {
    id: "brief",
    name: "Project brief.pdf",
    typeText: "PDF document",
    sizeText: "2.4 MB",
    status: "ready",
  },
  {
    id: "notes",
    name: "Release notes.md",
    typeText: "Markdown",
    sizeText: "42 KB",
    status: "uploading",
    progress: 64,
  },
  {
    id: "assets",
    name: "Brand assets.zip",
    typeText: "ZIP archive",
    sizeText: "8.1 MB",
    status: "error",
    error: "Preparation was interrupted. Retry this sample file.",
  },
];

export function AttachmentTrayDemo() {
  const [items, setItems] = useState(sample);
  const [status, setStatus] = useState(
    "Local sample files. Nothing is uploaded.",
  );
  const root = useRef<HTMLElement>(null);
  const reset = useRef<HTMLButtonElement>(null);
  const recovery = useRef<{
    id: string;
    index: number;
    source?: HTMLButtonElement;
  } | null>(null);
  useLayoutEffect(() => {
    const intent = recovery.current;
    recovery.current = null;
    if (
      !intent ||
      (document.activeElement !== document.body &&
        !(intent.source?.disabled && document.activeElement === intent.source))
    )
      return;
    const rows = Array.from(
      root.current?.querySelectorAll<HTMLElement>("[data-attachment-id]") ?? [],
    );
    const row =
      rows.find((x) => x.dataset.attachmentId === intent.id) ??
      rows[Math.min(intent.index, rows.length - 1)];
    (
      row?.querySelector<HTMLButtonElement>(
        '[data-attachment-action="remove"]:not(:disabled)',
      ) ?? reset.current
    )?.focus({ preventScroll: true });
  }, [items]);
  return (
    <div className="attachment-tray-demo">
      <TidalAttachmentTray
        ref={root}
        label="Attachments"
        attachments={items}
        onRemove={(item) => {
          recovery.current = {
            id: item.id,
            index: items.findIndex((x) => x.id === item.id),
          };
          setItems(items.filter((x) => x.id !== item.id));
          setStatus(`${item.name} removed from the local sample.`);
        }}
        onRetry={(item) => {
          recovery.current = {
            id: item.id,
            index: items.findIndex((x) => x.id === item.id),
          };
          setItems(
            items.map((x) =>
              x.id === item.id
                ? { ...x, status: "ready", error: undefined }
                : x,
            ),
          );
          setStatus(`${item.name} is ready in the local sample.`);
        }}
        actions={
          <button
            type="button"
            className="attachment-demo-advance"
            disabled={!items.some((x) => x.status === "uploading")}
            onClick={(event) => {
              recovery.current = {
                id: items.find((x) => x.status === "uploading")?.id ?? "",
                index: 0,
                source: event.currentTarget,
              };
              setItems(
                items.map((x) =>
                  x.status === "uploading"
                    ? { ...x, status: "ready", progress: 100 }
                    : x,
                ),
              );
              setStatus("Sample preparation completed locally.");
            }}
          >
            Complete sample
          </button>
        }
      />
      <div className="attachment-demo-footer">
        <p role="status">{status}</p>
        <button
          ref={reset}
          type="button"
          onClick={() => {
            setItems(sample);
            setStatus("Local sample files restored. Nothing is uploaded.");
          }}
        >
          Reset sample
        </button>
      </div>
    </div>
  );
}

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

{"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 label and consumer-owned attachments with unique ids, filename, status (queued, uploading, ready, error), optional sizeText/typeText/statusLabel/progress/error, native remove/retry button props and refs. Optional remove/retry callbacks receive the item and native event; caller button handlers run first and prevention cancels the callback. Root and per-item disabled states normalize with native disabled/aria-disabled; the consumer header-actions slot becomes inert while the root is disabled. Optional emptyMessage, actions, headingLevel and native section attrs/ref. Progress and Status badge are composed from accepted components. Identical filenames remain distinct by id. The consumer owns upload, retry, removal, focus after an accepted mutation and message submission. No file reads, uploads, storage or requests occur.
