Skip to content
Agent UI
PrimitivesComposer

Composer

Composer owns draft text and attachment state, auto-resizes its textarea, and exposes compound parts through dot notation. Build exactly the prompt bar your product needs without reimplementing keyboard handling.

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

tsx

Installation

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

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

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 { Composer } from "@agent-ui/react";
 
<Composer onSend={(text, files) => send(text, files)}>
<Composer.Input placeholder="Ask anything..." />
<div className="mt-2 flex items-center justify-between">
<div className="flex gap-1">
<Composer.SearchToggle />
<Composer.ThinkingToggle />
</div>
<Composer.SendButton />
</div>
</Composer>

API reference

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

API reference for this component
NameTypeDefaultDescription
onSend(text: string, attachments: File[]) => void—Called on Enter or send click when the draft is non-empty.
disabledbooleanfalseDisables the textarea and send button.
childrenReactNode—Composer parts: Input, SendButton, slots, toggles.
classNamestring—Inherits every native div attribute, including id, aria-*, data-*, onClick, and style.

Compound parts

Composer exposes these parts for composition.

Compound parts
PartDescription
Composer.InputAuto-resizing textarea; Enter sends, Shift+Enter adds a line.
Composer.SendButtonDisabled until text exists; clears the draft after send.
Composer.ProviderModelSlotInline slot for a model or provider control.
Composer.SkillSlotInline slot for skills, tools, or mentions.
Composer.AttachmentSlotInline slot for attachment chips.
Composer.SearchToggleGlobe toggle with aria-pressed state.
Composer.ThinkingToggleCycles off → low → medium → high with accessible labels.
Composer.MentionMenuListbox surface for @-mention suggestions.

Accessibility

The textarea has an accessible name, Enter and Shift+Enter behaviour, and the send button reports its disabled state.
Use it with the rest of the library

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

12 lines · copy-ready