This page as markdown: /chat-composer.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

ChatComposer

Status: stable

The input half of a conversation: one surface holding attachments, an auto-growing field, and its controls. Enter sends, Shift+Enter breaks the line (sendOn="mod-enter" swaps them for long-form replies; on touch, Return always breaks the line), and send becomes stop while a reply streams. allowEmpty sends attachments without text.

Keywords: chat input, composer, message input, prompt input, send message, ai chat, support chat, textarea

Usage

Pairs with MessageScroller to make a working chat. A single surface rather than an input with buttons parked beside it: attachments above, text in the middle, affordances along the bottom. Works controlled or uncontrolled — uncontrolled is the default because it is what the common case wants, and what lets a hook-free page shell ship a composer that actually types.

Best practices

Anatomy

Part Required Description
Attachments no Pending files as chips, above the field, inside the same surface.
Field yes An auto-growing Textarea, stripped of its own border and ring — the surface carries both — capped before it eats the transcript.
Controls yes Attach and any leading controls on the left; actions and the send/stop button on the right.
Footer no Helper text or a character counter below the controls.

Props

Name Type Default Description
value string — Controlled value. Omit for an uncontrolled composer that owns its own text.
defaultValue string "" Initial value when uncontrolled.
onValueChange (value: string) => void — Notified on every keystroke. Required when value is supplied.
onSend (value: string) => void — Called with the trimmed message. An uncontrolled composer clears itself afterwards; a controlled one is the caller's to clear. With allowEmpty the message can be "".
allowEmpty boolean false Let the reader send with no text, because the app has something else to send (pending attachments). Pass it only while that is true, allowEmpty={files.length > 0}; onSend then receives "".
placeholder string "Send a message…" Placeholder for the field.
sendOn "enter" | "mod-enter" "enter" Which key sends. enter for chat (Shift+Enter breaks the line). mod-enter for long-form replies such as an email or a support answer: Enter breaks the line and Cmd/Ctrl+Enter sends, so a paragraph break never mails a draft. Say so in footer ("Cmd+Enter to send"). On a touch device (pointer: coarse) enter behaves as mod-enter: a soft keyboard has no Shift+Return, so Return breaks the line and the send button sends.
busy boolean false A reply is streaming. Disables send, and swaps it for a stop control when onStop is supplied.
onStop () => void — Interrupt the in-flight reply. Supplying it turns send into stop while busy.
disabled boolean false Block sending entirely — over a limit, disconnected, read-only thread. Distinct from busy, which is temporary and offers a way out (stop).
invalid boolean false Mark the current text invalid. Colours the surface border and sets aria-invalid on the field.
attachments ReactNode — Attachment chips, shown above the field.
leading ReactNode — Controls on the left of the footer row — model picker, tool toggles.
actions ReactNode — Extra controls left of the send button.
onAttach () => void — Attach handler. Supplying it renders the built-in attach button.
label string "Message" Accessible label for the field.
sendLabel string "Send message" Accessible label for the send button.
stopLabel string "Stop generating" Accessible label for the stop button.
attachLabel string "Add attachment" Accessible label for the built-in attach button (rendered when onAttach is set).
footer ReactNode | ((state: { sendOn: "enter" | "mod-enter" }) => ReactNode) — Helper text or counter below the controls. For a keyboard hint pass a function: it receives the send key in effect (touch turns enter into mod-enter), and returning null removes the row, e.g. footer={({ sendOn }) => sendOn === "enter" ? "Enter to send" : null}.
fieldRef Ref — Ref to the underlying textarea — for focusing after a send, or on mount, and the extension point for anything that listens to the field. Pass useCaretTrigger's fieldRef here for mentions and slash commands (CaretMenu). An Enter another listener already handled (preventDefault()) does not send.
motion "full" | "subtle" | "off" "full" How much motion this component uses: full (default) inherits the app's policy, subtle keeps feedback and drops the flourish, off stills it. It can only turn motion down — it never overrides a reader's reduce-motion setting. Under subtle the field snaps to its new height and the send/stop glyphs swap without the morph.
...form props Omit<ComponentPropsWithRef<"form">, "onSubmit" | "defaultValue"> — Spread onto the form element. Use onSend rather than onSubmit.

Variants

Tokens used

field, field-border, ring, destructive, foreground, muted-foreground, primary, primary-foreground, secondary, secondary-foreground, accent, accent-foreground

Motion

Accessibility

Related

Examples

Uncontrolled — the common case

import { ChatComposer } from "@sableui/react"

<ChatComposer onSend={(text) => send(text)} onAttach={pickFile} />

Streaming, with a stop control

import { ChatComposer } from "@sableui/react"

<ChatComposer onSend={send} busy={isStreaming} onStop={stop} placeholder="Ask a follow-up…" />

Controlled, with pending attachments

import { Attachment, Button, ChatComposer, Icon } from "@sableui/react"

<ChatComposer
	value={draft}
	onValueChange={setDraft}
	onSend={(text) => { post(text, files); setDraft("") }}
	onAttach={pickFile}
	attachments={files.map((f) => (<Attachment key={f.id} variant="media" name={f.name} thumbnail={f.url} actions={<Button variant="floating" size="icon-xs" aria-label="Remove" onClick={() => drop(f.id)}><Icon name="xmark" /></Button>} />))}
	footer={`${draft.length} / 4000`}
	invalid={draft.length > 4000}
/>

Attachments sent without text

import { Attachment, ChatComposer } from "@sableui/react"

<ChatComposer
	onSend={(text) => post(text, files)}
	allowEmpty={files.length > 0}
	onAttach={pickFile}
	attachments={files.map((f) => <Attachment key={f.id} name={f.name} meta={f.size} />)}
/>

A working chat, end to end

import { Bubble, ChatComposer, Marker, Message, MessageScroller } from "@sableui/react"

<div className="flex h-128 flex-col gap-3">
	<MessageScroller className="flex-1 min-h-0">
		{messages.map((m) => (<Message key={m.id} messageId={m.id} align={m.mine ? "end" : "start"}><Bubble variant={m.mine ? "primary" : "muted"} align={m.mine ? "end" : "start"}>{m.body}</Bubble></Message>))}
		{streaming ? <Marker icon="spinner" spin shimmer>Thinking…</Marker> : null}
	</MessageScroller>
	<ChatComposer onSend={send} busy={streaming} onStop={stop} />
</div>