The message box of a chat with an AI assistant. The textarea grows with the text up to a maximum height, Enter sends and Shift+Enter adds a line (or Ctrl/⌘+Enter sends, if you prefer). Files are attached with the paperclip, by drag and drop or by pasting a screenshot. While a reply streams, the send button becomes a stop button. Parts are composable: put your own model picker or toggles into the toolbar.
Browser Support
Baseline Newly available2 featuresDetails
The textarea grows with its text up to max-height. Without it a small script sets the height from scrollHeight on every change.
Draws the focus ring around the whole box when the textarea has keyboard focus, and the red border when the text is over maxLength. Without it the border still changes colour through :focus-within, and the counter turns red.
Preview
Installation
Usage
"use client"
import { useRef, useState } from "react"
import {
PromptInput,
PromptInputAttachButton,
PromptInputAttachments,
PromptInputCounter,
type PromptInputStatus,
PromptInputSubmit,
PromptInputTextarea,
PromptInputToolbar,
} from "@/components/ui/prompt-input"
export function Composer() {
const [status, setStatus] = useState<PromptInputStatus>("idle")
const controller = useRef<AbortController | null>(null)
return (
<PromptInput
status={status}
maxLength={2000}
onStop={() => controller.current?.abort()}
onSubmit={async ({ text, files }) => {
controller.current = new AbortController()
setStatus("streaming")
try {
await sendToModel(text, files, controller.current.signal)
} finally {
setStatus("idle")
}
}}
>
<PromptInputAttachments />
<PromptInputTextarea />
<PromptInputToolbar>
<PromptInputAttachButton />
<PromptInputCounter className="ml-auto" />
<PromptInputSubmit />
</PromptInputToolbar>
</PromptInput>
)
}Examples
Compact reply
The same parts in one row: className on PromptInput turns the column into a wrapping row, and the attachments take a full line above it.
- Priya: Can we move the design review to Thursday?
<PromptInput
onSubmit={({ text }) => reply(text)}
placeholder="Reply to Priya"
className="flex-row flex-wrap items-end gap-1 rounded-3xl p-1"
>
<PromptInputAttachments className="basis-full" />
<PromptInputAttachButton />
<PromptInputTextarea className="max-h-32 min-h-8 min-w-0 flex-1 basis-0 px-1 py-1.5" />
<PromptInputSubmit />
</PromptInput>Feedback with Ctrl/⌘ + Enter
submitOn="mod+enter" leaves Enter for new lines. Above maxLength the counter turns red and sending is blocked.
<PromptInput
submitOn="mod+enter"
maxLength={280}
placeholder="What should we improve in the checkout flow?"
onSubmit={({ text }) => sendFeedback(text)}
>
<PromptInputTextarea className="min-h-20" />
<PromptInputToolbar>
<span className="text-muted-foreground text-xs">Ctrl/⌘ + Enter to send</span>
<PromptInputCounter className="ml-auto" />
<PromptInputSubmit />
</PromptInputToolbar>
</PromptInput>Default layout
Without children PromptInput renders the attachments, the textarea and a toolbar with the attach button, the counter and send. accept limits the picker, drop and paste to images and PDF.
<PromptInput
accept="image/*,.pdf"
placeholder="Describe the bug, attach a screenshot or PDF"
onSubmit={({ text, files }) => createIssue(text, files)}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | Controlled text |
| defaultValue | string | "" | Initial text when uncontrolled |
| onValueChange | (value: string) => void | - | Called on every change of the text |
| onSubmit | (message: { text: string; files: File[] }) => void | - | Called with the trimmed text and the attached files. The field is cleared afterwards |
| status | "idle" | "submitting" | "streaming" | "idle" | submitting shows a spinner, streaming turns the send button into stop. Both block sending |
| onStop | () => void | - | Called by the stop button while streaming |
| placeholder | string | "Send a message…" | Placeholder of the textarea |
| maxLength | number | - | Soft limit: the counter turns red and sending is blocked above it, the text itself is not cut |
| submitOn | "enter" | "mod+enter" | "enter" | Which shortcut sends. With enter, Shift+Enter adds a new line |
| accept | string | - | File types for the picker, drop and paste, as in the accept attribute |
| maxFiles | number | 10 | Maximum number of attachments |
| disabled | boolean | false | Disables the whole box |
| labels | Partial<PromptInputLabels> | English | Texts for screen readers and the drop overlay |
| className | string | - | Additional CSS classes for the form |
Components
| Component | Description |
|---|---|
| PromptInput | The form and its state. Without children renders the default layout |
| PromptInputTextarea | Growing textarea. Handles Enter, IME composition and pasted files |
| PromptInputAttachments | Chips of attached files with image previews |
| PromptInputToolbar | Row for buttons and your own controls. Server component |
| PromptInputAttachButton | Paperclip button that opens the file picker |
| PromptInputCounter | “12 / 500” counter, only with maxLength |
| PromptInputSubmit | Send button, spinner while submitting, stop while streaming |
| usePromptInput() | State and actions for your own parts: text, attachments, submit… |
Features
- IME safe. Enter that confirms a Chinese or Japanese composition does not send the message.
- Paste and drop. A pasted screenshot becomes an attachment; when the clipboard also has text, the text is kept. Dropping is handled by useFileDrop.
- Server parts. PromptInput with its default layout and the toolbar are server components; state, keys and files live in prompt-input.client.