# Chat Composer

A chat panel with conversation tabs, a thread of messages and a composer.

A compact chat panel with conversation tabs, a thread and a composer. A pill tab strip switches between conversations (our tabs; panels swap instantly), the thread is made of Message components (the user's prompts as bubbles, the agent's steps as labelled messages), and a composer at the bottom sends. Enter sends, Shift+Enter starts a new line, nothing sends during an IME composition. Suggestion pills fill the composer; while the agent works they give way to a shimmering status and send turns into stop. The card keeps its height: the thread scrolls.

Kind: block · Category: Agent · Status: beta · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add chat-composer
```

It writes the folder `chat-composer/` into the project's ui folder (`index.ts`, `chat-composer.tsx`, `ChatComposer.vue`, `ChatComposer.svelte`, `chat-composer.recipe.ts`), and what it is built from: [Tabs](/components/tabs.md), [Button](/components/button.md), [Shimmer](/components/shimmer.md), [Tooltip](/components/tooltip.md), [Message](/components/message.md), [Prompt Bar](/components/prompt-bar.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { ChatComposer } from "@/components/ui/chat-composer";
```

```vue
import { ChatComposer } from "@/components/ui/chat-composer";
```

```svelte
import { ChatComposer } from "$lib/components/ui/chat-composer";
```

## Parts

In the DOM the root carries `data-slot="chat-composer"` and each part `data-slot="chat-composer-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `chat-composer` |  | Fixed height; the thread takes the room the composer leaves. |
| `tabs` | `div` | `chat-composer-tabs` |  | The real Tabs (pill): the strip is the header, each panel holds one conversation and scrolls. Marked data-chat-composer="tabs" on its root |
| `thread` | `div` | `chat-composer-thread` | repeats | role=log; one per tab panel |
| `message` | `article` | `chat-composer-message` | repeats | The real Message, marked data-chat-composer="message": the user's prompt as its bubble at the end (role user); an agent step as role assistant with the step's label as its name, the source as its Chip and the duration ("for 4s") as its time. A message that arrives after mount carries data-enter (set and cleared by the shared helper) while it rises in. |
| `composer` | `div` | `chat-composer-composer` |  |  |
| `suggestions` | `div` | `chat-composer-suggestions` | optional | One row of suggestion Buttons; scrolls sideways. Hidden while busy. |
| `suggestion` | `button` | `chat-composer-suggestion` | repeats | The real Button (outline, sm), marked data-chat-composer="suggestion" |
| `status` | `div` | `chat-composer-status` | optional | role=status; a Shimmer label in the suggestions row place while busy |
| `field` | `div` | `chat-composer-field` |  | The input box; pressing its padding focuses the textarea |
| `input` | `textarea` | `chat-composer-input` |  | Grows with its content up to 96px, then scrolls |
| `footer` | `div` | `chat-composer-footer` |  |  |
| `send` | `button` | `chat-composer-send` |  | The real Button (primary sm square) with our Tooltip naming it, marked data-chat-composer="send". aria-label Send, or Stop generating while busy; disabled while the draft is empty |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `tabs` | `{ value: string; label: string; messages?: Array<{ role: 'user', text } \| { role: 'agent', text, label?, source?, time? }> }[]` |  | Bindable (React: `defaultTabs` and `onTabsChange`; Vue: `v-model:tabs`; Svelte: `bind:tabs`). Conversations in order. Sending appends the user's message to the selected tab's messages (tabsChange); the host appends the agent's reply. Each message renders as a Message. |
| `tab` | `string` |  | Bindable (React: `defaultTab` and `onTabChange`; Vue: `v-model:tab`; Svelte: `bind:tab`). Selected conversation. Defaults to the first. |
| `value` | `string` | `""` | Bindable (React: `defaultValue` and `onValueChange`; Vue: `v-model:value`; Svelte: `bind:value`). The draft. |
| `suggestions` | `{ text: string }[]` |  | Prompts offered as pills (plain strings); choosing one puts it in the composer. |
| `busy` | `boolean` | `false` | The agent is working: the status replaces the suggestions, send becomes stop, Enter does not send. |
| `status` | `string` | `"Thinking"` | Label of the busy status (an ellipsis is added). |
| `placeholder` | `string` | `"Write a message…"` |  |
| `aria-label` | `string` | `"Conversations"` | Name of the tab list. |
| `labels` | `object` |  | The fixed strings, partial: { message (the textarea's name), send, stop (the send button's name and tooltip, idle and busy), time ('for {time}', a step's duration) }. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `valueChange` | (value: string) |
| `tabChange` | (tab: string) |
| `tabsChange` | (tabs: ChatComposerTab[]) |
| `submit` | ({ value, tab }) Enter or the send button; value is trimmed; the composer then clears |
| `stop` | () the stop button while busy |

## States

`focus-within`, `busy`, `disabled`, `hover`, `press`, `focus-visible`

## Keyboard and accessibility

Role: tablist + tabpanel (role=log thread) + textarea.

Keyboard:

- Tab order: the selected tab, the panel, each suggestion, the textarea, send
- Tab strip: ArrowLeft / ArrowRight move and select (wrapping), Home / End jump; panels swap instantly
- Textarea: Enter sends; Shift+Enter inserts a newline; nothing sends during an IME composition or while busy
- Suggestion: Enter / Space put it in the composer and move focus to the end of the textarea
- Send / stop: Enter / Space

Notes:

- The thread is role=log, so a new message is announced once; the busy status is role=status.
- Send is icon-only: aria-label Send, Stop generating while busy.
- 16px text on coarse pointers so iOS does not zoom the page; enterkeyhint=send.

## Motion

- panels: swap instantly; the strip's indicator is the tabs component's (slides under the pointer, jumps under the keyboard)
- message: a message that arrives after mount rises in once (fndn-fade-up, duration.enter, easing.out-strong); messages present at mount and tab swaps never animate
- thread: an arriving message scrolls the thread to it smoothly (scrollTo, behavior smooth; instant under prefers-reduced-motion); at mount and when a panel is shown again it opens at the end at once
- field: border colour over duration.base on focus
- status / suggestions: swap instantly; the shimmer is the shimmer component's loop (static under reduced motion)
- buttons: the button component's press scale and colour

## Tokens

`color.surface`, `color.field`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.line`, `color.line-strong`, `shadow.card`, `radius.window`, `radius.control`, `text.xs`, `text.sm`, `text.md`, `duration.base`, `duration.enter`, `easing.out-strong`

## Dependencies

- [Tabs](/components/tabs.md)
- [Button](/components/button.md)
- [Shimmer](/components/shimmer.md)
- [Tooltip](/components/tooltip.md)
- [Message](/components/message.md)
- [Prompt Bar](/components/prompt-bar.md)

## Examples

### Ask why a deploy failed

React · `conversation.tsx`

```tsx
import type { ComponentProps } from "react";
import { ChatComposer } from "@/components/ui/chat-composer";

type Props = ComponentProps<typeof ChatComposer>;

const tabs: Props["defaultTabs"] = [
  {
    value: "deploy-482",
    label: "Deploy #482",
    messages: [
      {
        role: "user",
        text: "Why did the 14:05 deploy of harbor/web fail?",
      },
      {
        role: "agent",
        label: "CI logs",
        source: "github_actions",
        time: "6s",
        text: "The test step failed: 3 tests in booking-calendar.test.ts time out after 5,000 ms.",
      },
      {
        role: "agent",
        label: "Cause",
        source: "harbor/web",
        time: "3s",
        text: "Commit 9f2c1ab changed the slot query to /v2/availability, but the tests still mock /v1/slots.",
      },
    ],
  },
  {
    value: "refunds",
    label: "Refund queue",
    messages: [
      {
        role: "user",
        text: "Which refunds are waiting on finance?",
      },
      {
        role: "agent",
        label: "Stripe",
        source: "billing-service",
        time: "2s",
        text: "4 refunds over $500 wait for Daniel Okafor. The oldest is Kestrel Logistics, $1,240, 3 days ago.",
      },
    ],
  },
];

const suggestions = ["Roll back to #481", "Fix the mocks", "Notify #deploys"];

export default function Conversation() {
  return (
    <ChatComposer
      defaultTabs={tabs}
      defaultTab="deploy-482"
      suggestions={suggestions}
      placeholder="Ask a follow-up or tag a teammate with @"
      style={{ width: 380 }}
    />
  );
}
```

Vue · `conversation.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { ChatComposer, type ChatComposerTab } from "@/components/ui/chat-composer";

const tabs = ref<ChatComposerTab[]>([
  {
    value: "deploy-482",
    label: "Deploy #482",
    messages: [
      {
        role: "user",
        text: "Why did the 14:05 deploy of harbor/web fail?",
      },
      {
        role: "agent",
        label: "CI logs",
        source: "github_actions",
        time: "6s",
        text: "The test step failed: 3 tests in booking-calendar.test.ts time out after 5,000 ms.",
      },
      {
        role: "agent",
        label: "Cause",
        source: "harbor/web",
        time: "3s",
        text: "Commit 9f2c1ab changed the slot query to /v2/availability, but the tests still mock /v1/slots.",
      },
    ],
  },
  {
    value: "refunds",
    label: "Refund queue",
    messages: [
      {
        role: "user",
        text: "Which refunds are waiting on finance?",
      },
      {
        role: "agent",
        label: "Stripe",
        source: "billing-service",
        time: "2s",
        text: "4 refunds over $500 wait for Daniel Okafor. The oldest is Kestrel Logistics, $1,240, 3 days ago.",
      },
    ],
  },
]);

const tab = ref("deploy-482");

const suggestions = ["Roll back to #481", "Fix the mocks", "Notify #deploys"];
</script>

<template>
  <ChatComposer
    v-model:tabs="tabs"
    v-model:tab="tab"
    :suggestions="suggestions"
    placeholder="Ask a follow-up or tag a teammate with @"
    style="width: 380px"
  />
</template>
```

Svelte · `conversation.svelte`

```svelte
<script lang="ts">
  import { ChatComposer, type ChatComposerTab } from "$lib/components/ui/chat-composer";

  let tabs = $state<ChatComposerTab[]>([
    {
      value: "deploy-482",
      label: "Deploy #482",
      messages: [
        {
          role: "user",
          text: "Why did the 14:05 deploy of harbor/web fail?",
        },
        {
          role: "agent",
          label: "CI logs",
          source: "github_actions",
          time: "6s",
          text: "The test step failed: 3 tests in booking-calendar.test.ts time out after 5,000 ms.",
        },
        {
          role: "agent",
          label: "Cause",
          source: "harbor/web",
          time: "3s",
          text: "Commit 9f2c1ab changed the slot query to /v2/availability, but the tests still mock /v1/slots.",
        },
      ],
    },
    {
      value: "refunds",
      label: "Refund queue",
      messages: [
        {
          role: "user",
          text: "Which refunds are waiting on finance?",
        },
        {
          role: "agent",
          label: "Stripe",
          source: "billing-service",
          time: "2s",
          text: "4 refunds over $500 wait for Daniel Okafor. The oldest is Kestrel Logistics, $1,240, 3 days ago.",
        },
      ],
    },
  ]);

  let tab = $state("deploy-482");

  const suggestions = ["Roll back to #481", "Fix the mocks", "Notify #deploys"];
</script>

<ChatComposer
  bind:tabs={tabs}
  bind:tab={tab}
  suggestions={suggestions}
  placeholder="Ask a follow-up or tag a teammate with @"
  style="width: 380px"
/>
```

### Agent reading logs during an incident

React · `busy.tsx`

```tsx
import type { ComponentProps } from "react";
import { ChatComposer } from "@/components/ui/chat-composer";

type Props = ComponentProps<typeof ChatComposer>;

const tabs: Props["defaultTabs"] = [
  {
    value: "incident",
    label: "API latency",
    messages: [
      {
        role: "user",
        text: "p95 latency on harbor/api doubled at 09:40. What changed?",
      },
    ],
  },
  {
    value: "deploy-482",
    label: "Deploy #482",
  },
];

const suggestions = ["Compare with yesterday", "Open the dashboard"];

export default function Busy() {
  return (
    <ChatComposer
      defaultTabs={tabs}
      defaultTab="incident"
      busy
      status="Reading the request logs"
      suggestions={suggestions}
      style={{ width: 380 }}
    />
  );
}
```

Vue · `busy.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { ChatComposer, type ChatComposerTab } from "@/components/ui/chat-composer";

const tabs = ref<ChatComposerTab[]>([
  {
    value: "incident",
    label: "API latency",
    messages: [
      {
        role: "user",
        text: "p95 latency on harbor/api doubled at 09:40. What changed?",
      },
    ],
  },
  {
    value: "deploy-482",
    label: "Deploy #482",
  },
]);

const tab = ref("incident");

const suggestions = ["Compare with yesterday", "Open the dashboard"];
</script>

<template>
  <ChatComposer
    v-model:tabs="tabs"
    v-model:tab="tab"
    busy
    status="Reading the request logs"
    :suggestions="suggestions"
    style="width: 380px"
  />
</template>
```

Svelte · `busy.svelte`

```svelte
<script lang="ts">
  import { ChatComposer, type ChatComposerTab } from "$lib/components/ui/chat-composer";

  let tabs = $state<ChatComposerTab[]>([
    {
      value: "incident",
      label: "API latency",
      messages: [
        {
          role: "user",
          text: "p95 latency on harbor/api doubled at 09:40. What changed?",
        },
      ],
    },
    {
      value: "deploy-482",
      label: "Deploy #482",
    },
  ]);

  let tab = $state("incident");

  const suggestions = ["Compare with yesterday", "Open the dashboard"];
</script>

<ChatComposer
  bind:tabs={tabs}
  bind:tab={tab}
  busy
  status="Reading the request logs"
  suggestions={suggestions}
  style="width: 380px"
/>
```

### Start a new chat with a drafted prompt

React · `draft.tsx`

```tsx
import type { ComponentProps } from "react";
import { ChatComposer } from "@/components/ui/chat-composer";

type Props = ComponentProps<typeof ChatComposer>;

const tabs: Props["defaultTabs"] = [
  {
    value: "new",
    label: "New chat",
  },
];

const suggestions = ["Summarize today's tickets", "Find accounts at risk"];

export default function Draft() {
  return (
    <ChatComposer
      defaultTabs={tabs}
      defaultValue="Draft a reply to Brightline Dental about the double-booked Tuesday slots"
      suggestions={suggestions}
      style={{ width: 380 }}
    />
  );
}
```

Vue · `draft.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { ChatComposer } from "@/components/ui/chat-composer";

const tabs = ref([
  {
    value: "new",
    label: "New chat",
  },
]);

const value = ref("Draft a reply to Brightline Dental about the double-booked Tuesday slots");

const suggestions = ["Summarize today's tickets", "Find accounts at risk"];
</script>

<template>
  <ChatComposer
    v-model:tabs="tabs"
    v-model:value="value"
    :suggestions="suggestions"
    style="width: 380px"
  />
</template>
```

Svelte · `draft.svelte`

```svelte
<script lang="ts">
  import { ChatComposer } from "$lib/components/ui/chat-composer";

  let tabs = $state([
    {
      value: "new",
      label: "New chat",
    },
  ]);

  let value = $state("Draft a reply to Brightline Dental about the double-booked Tuesday slots");

  const suggestions = ["Summarize today's tickets", "Find accounts at risk"];
</script>

<ChatComposer
  bind:tabs={tabs}
  bind:value={value}
  suggestions={suggestions}
  style="width: 380px"
/>
```

## Recipe

`chat-composer.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* chat-composer — a fixed-height chat card: tab strip (our Tabs), a scrolling thread per tab, and
 * a composer. The card never changes shape: the open panel takes the room the composer leaves and
 * scrolls. Panels swap instantly; only a message that arrives after mount moves (watchThreads sets
 * and clears data-enter).
 *
 * Composed: Tabs (only its place in the card is passed, `tabs`), Message (each message of a
 * thread, the person's bubble and the agent's steps; marked data-chat-composer="message"), Shimmer
 * (the busy status), Button (suggestions, send; marked data-chat-composer="suggestion|send").
 * Tabs passes on no data-* attribute in React and Svelte yet, so it is unmarked. Focus on the field shows the caret and nothing
 * else: focus never recolours an edge. Author text takes its direction from its
 * own first letter (plaintext). */

const PLAIN = "[unicode-bidi:plaintext]";

export const chatComposer = tv({
  slots: {
    base: [
      "flex flex-col w-full max-w-[380px] h-[288px] min-w-0 overflow-hidden",
      "rounded-window bg-surface shadow-card text-ink",
    ],
    /* the Tabs root (fill): the strip is the card's header, the open panel the thread's scroller.
     * The Tabs' header part (an empty headerClass) is the strip's row and carries the hairline, so
     * it runs the whole width under the list and, while the strip overflows, under the all-tabs
     * menu after it (the list's edge fade never touches it). The list is flush with the card that
     * clips it, its 6px padding holds the focus ring; the menu keeps 6px from the card's edge. A
     * long name stops at 180px. */
    tabs: [
      "flex-1 min-h-0",
      "[&>[data-slot=tabs-header]]:border-b [&>[data-slot=tabs-header]]:border-line",
      "[&>[data-slot=tabs-header]>[data-slot=tabs-list]]:p-1.5 [&>[data-slot=tabs-header]>[data-tabs=more]]:pe-1.5",
      "[&_[data-slot=tabs-trigger]]:max-w-[180px]",
      "[&>[data-slot=tabs-content]]:flex-1 [&>[data-slot=tabs-content]]:min-h-0 [&>[data-slot=tabs-content]]:overflow-y-auto",
      "[&>[data-slot=tabs-content]]:pt-2.5 [&>[data-slot=tabs-content]]:px-3",
      "[&>[data-slot=tabs-content]]:pb-1 [&>[data-slot=tabs-content]]:text-ink",
      /* the panel is focusable (it scrolls) and fills the card, which clips: its ring sits inside */
      "[&>[data-slot=tabs-content]:focus-visible]:outline-offset-[-2px]",
    ],
    thread: "flex flex-col gap-2.5 min-w-0",
    /* on the Message (marked data-chat-composer="message"): one that arrives after mount rises in */
    message: "data-enter:animate-fade-up",
    composer: "flex flex-col gap-1.5 shrink-0 min-w-0 p-1.5",
    /* suggestions and the busy status share one 32px row, so swapping them never moves anything.
     * The suggestions scroll sideways, which clips them on every side: the row is 4px larger all
     * round than the 28px pills (their focus ring reaches 4px past them) and takes that back with
     * negative margins. */
    suggestions: [
      "flex items-center gap-1 min-w-0 h-9 -my-0.5 -mx-1 p-1 scroll-px-1",
      "overflow-x-auto overscroll-x-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
    ],
    suggestion: "max-w-[220px]",
    status: "flex items-center gap-1 min-w-0 h-8 px-2 text-xs",
    field: "flex flex-col gap-2 min-w-0 p-2.5 border border-line rounded-control bg-field cursor-text",
    /* under 16px iOS zooms into the field */
    input: [
      "block w-full min-w-0 min-h-[18px] max-h-24 m-0 p-0 border-0 bg-transparent",
      "[font-family:inherit] [font-style:inherit] [font-weight:inherit] [font-stretch:inherit] [font-variant:inherit]",
      "text-sm leading-[18px] text-ink placeholder:text-ink-3 resize-none outline-none",
      "wrap-anywhere overflow-y-auto [field-sizing:content] pointer-coarse:text-[16px] pointer-coarse:leading-[20px]",
      /* the placeholder too: unicode-bidi does not inherit into it */
      PLAIN, "placeholder:[unicode-bidi:plaintext] [&:dir(ltr)]:text-left [&:dir(rtl)]:text-right",
    ],
    footer: "flex items-center justify-end min-w-0",
    send: "cursor-pointer",
  },
});

export type ChatComposerRecipeProps = VariantProps<typeof chatComposer>;
```
