Input
A chat message composer with auto-growing input, file attachments, toolbar slots, and a send button that morphs into stop while streaming.
import { PromptInput } from '@uthereal/ui/prompt-input'Prompt input playground
Overview
PromptInput is a standalone chat message composer. The attach button and optional toolbar actions sit at the inline start beside a rounded text field that grows smoothly from minRows to maxRows lines (6 by default) before scrolling. The send button rides the field's bottom-end edge, filling with the accent color when ready and morphing into a stop button while a reply streams. Attached files appear in a scrollable tray above the row with thumbnails, upload progress bars, retry controls, and remove badges.
The composer never sends messages or uploads files on its own: it reports text, accepted files, and named actions to your application, while you pass back status and attachments.
Usage
Basic composer
'use client'
import { useState } from 'react'
import { PromptInput } from '@uthereal/ui/prompt-input'
export function Composer({
sendMessage,
stopReply,
}: {
sendMessage: (text: string) => Promise<void>
stopReply: () => void
}) {
const [status, setStatus] = useState<'idle' | 'submitting' | 'streaming'>(
'idle',
)
return (
<PromptInput
status={status}
onSubmit={async (text) => {
setStatus('submitting')
await sendMessage(text)
setStatus('streaming')
}}
onStop={() => {
stopReply()
setStatus('idle')
}}
/>
)
}Composing with Dictation
Use renderToolbarEnd to place Dictation at the inline-end edge of the composer row with zero coupling between components. When the user speaks, append or commit the transcript directly into controlled value state.
'use client'
import { useState } from 'react'
import { PromptInput } from '@uthereal/ui/prompt-input'
import { Dictation } from '@uthereal/ui/dictation'
export function VoiceComposer({ onSend }: { onSend: (text: string) => void }) {
const [value, setValue] = useState('')
return (
<PromptInput
value={value}
onValueChange={setValue}
onSubmit={(text) => {
onSend(text)
setValue('')
}}
renderToolbarEnd={({ disabled, status }) => (
<Dictation
size="md"
disabled={disabled || status !== 'idle'}
onCommit={(spoken) =>
setValue((prev) => (prev ? `${prev.trimEnd()} ${spoken}` : spoken))
}
/>
)}
/>
)
}Examples
Attachments and streaming states
Uploading and failed file attachments alongside a streaming composer in dark mode with the soft variant.
Toolbar actions
Leading tool buttons (actions) paired with custom placeholder copy and soft fill styling.
Attachments & statuses
File picking, pasting, and drag-and-drop run through @zag-js/file-upload validation (accept, maxSize, maxFiles). Valid files reach onFilesAccept(files); invalid ones reach onFilesReject(rejections). Set maxFiles={0} to disable attachments and hide the attach button.
Attachment status | Display |
|---|---|
pending | Waiting icon and statusLabels.pending text. |
running | Spinner, statusLabels.running, and bottom progress bar (progress). |
complete | 56px image preview thumbnail or 168×56 file card with binary size. |
error | Danger border/icon, error reason, and optional Retry button (retryAction). |
A message can be submitted when status is idle, the input is neither disabled nor readOnly, all attachments are complete, and either trimmed text or at least one attachment is present.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Message" | Accessible name of the text field, e.g. "Message". Hidden by default: a chat composer is named by its context. |
hideLabel | booleanDefault: true | Hide the label visually (the default); it is still announced. Show it when the composer sits in a form. |
description | string— | Supporting text below the field, announced with it. Use it for format hints and constraints. |
error | string— | Validation message from your application. Setting it marks the field invalid; the message is linked to the field and announced politely. |
required | booleanDefault: false | Marks the field as required for assistive technology and shows an indicator. Your application validates the value. |
readOnly | booleanDefault: false | The value can be focused, selected, and copied, but not edited. It is still submitted with a form. |
disabled | booleanDefault: false | Unavailable and removed from the tab order. A disabled field is not submitted with a form. |
name | string— | Native form field name, submitted with the value in a form. |
placeholder | stringDefault: "Message" | Text shown while the field is empty; "Message" by default, as in Arc. Never a substitute for the label. |
defaultValue | stringDefault: "" | Initial text. Later argument edits do not reset an existing instance; use value and onValueChange to control it. |
minRows | integerDefault: 1 | Visible lines when empty, from 1 to 20. |
maxRows | integerDefault: 6 | Lines shown before the text scrolls: 6 by default, as in Arc, up to 20. Values below minRows act as minRows. |
maxLength | integer— | Maximum number of characters the user can type. Omit it for no limit. |
status | idle | submitting | streamingDefault: "idle" | idle; submitting while your application sends the message (the send button shows a spinner); streaming while the reply arrives (the send button becomes a stop button). |
submitLabel | stringDefault: "Send" | Accessible name and tooltip of the send button. |
stopLabel | stringDefault: "Stop" | Accessible name and tooltip of the stop button. |
sendingLabel | stringDefault: "Sending" | Announced while submitting. |
submitOnEnter | booleanDefault: true | Enter sends and Shift+Enter starts a new line. Turn it off to send only with the button. |
submitAction | string— | Name of an action registered by your application, sent with the message. Read the text from the composer state. |
stopAction | string— | Name of an action registered by your application, sent when the stop button is pressed. |
actions | PromptAction[]Default: [] | Up to six icon buttons after the attach button, at the start of the row, each with a stable ID, a label (its accessible name and tooltip), an icon and an action. |
attachments | PromptAttachment[]Default: [] | Attached files with their upload status (pending, running with progress, complete or error), described by your application. A preview URL shows an image as a 56px thumbnail; other files show as a card. |
maxFiles | integerDefault: 10 | Most attachments (10 by default). The attach button shows by default, as in Arc; your application uploads the files it reports. 0 hides the attach button and turns off pasting and dropping files. |
accept | string[]— | Accepted file types as MIME types ("image/*") or extensions (".pdf"). Omit it to accept any file. |
maxSize | integer— | Largest accepted file in bytes. Omit it for no limit. |
attachLabel | stringDefault: "Attach files" | Accessible name of the attach button. |
dropLabel | stringDefault: "Drop files to attach" | Shown in the box in place of the placeholder while files are dragged onto the composer. |
attachmentsLabel | stringDefault: "Attachments" | Accessible name of the list of attached files. |
statusLabels | FileStatusLabels— | Status text of an attachment per upload state. |
removeAction | string— | Name of an action registered by your application, sent with the attachment ID to remove it. |
retryAction | string— | Name of an action registered by your application, sent with the attachment ID to retry a failed upload. |
removeLabel | stringDefault: "Remove {name}" | Accessible name of each remove button; {name} is the file name. |
retryLabel | stringDefault: "Retry {name}" | Accessible name of each retry button; {name} is the file name. |
variant | outline | softDefault: "outline" | Composer surface: outline (a bordered field) or soft (a tinted fill). |
size | sm | md | lgDefault: "md" | Icon size of the buttons and attachments. The box keeps Arc’s 16px text and 32px send button at every size. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | PromptInputTheme— | Color mode, accent, and tokens of the field. The buttons follow the mode and accent. See Theming. |
motion | none | subtle | expressiveDefault: "subtle" | The box growing with its text, attachments popping in, the send arrow swapping on each send, and button presses. System reduced-motion preferences take precedence (Arc’s fades: attachments fade, the send arrow crossfades, the tray and box jump). |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
value, onValueChange(value) | Control the composer text; onValueChange('') fires after sending. |
onSubmit(value) | Receives trimmed text on send before the field clears. |
onStop() | Called when the stop button is pressed while status="streaming". |
onAction(action, itemId?) | Receives submitAction, stopAction, toolbar action IDs, and attachment IDs. |
onFilesAccept / onFilesReject | Picked, pasted, or dropped files that passed or failed accept/maxSize/maxFiles. |
renderToolbar(state) | Extra controls after actions, before the text box (e.g., a model picker). |
renderToolbarEnd(state) | Trailing controls at the inline-end of the row (e.g., Dictation). |
renderIcon(name, context) | Replace named icons (file, status, remove, retry, attach, send, stop). |
ref | Forwards directly to the underlying <textarea> element. |
preset, tokens, className, style | Application defaults, --ui-* token overrides, and root styling. |
Keyboard & accessibility
| Key | Action |
|---|---|
Enter | Sends the message when submitOnEnter is true (ignores IME compose). |
Shift+Enter | Inserts a newline without sending. |
Tab | Moves across attachment controls, toolbar buttons, textarea, and send/stop. |
- The
<textarea>is named bylabel(visually hidden by default viahideLabel) and wired todescriptionanderrorviaaria-describedby. - The send button stays focusable while empty (
aria-disabled="true"), morphs in place into Stop while streaming without losing focus, and announcessendingLabelvia a pre-mounted politerole="status"live region outside the button while submitting. - Removing an attachment moves focus to the next attachment's remove button or returns focus to the
<textarea>. - All spacing and alignment use logical CSS properties for
dir="rtl"support, andforced-colors: activemaps borders, error outlines, send/remove fills, and focus rings to system colors.
Motion & theming
The text box height follows content on the smooth spring (0.4s, bounce 0). Attachment chips pop in (scale: 0.9, 2px blur) on a spring (0.3s, bounce 0.22) and reflow cleanly when siblings exit. The send button morphs fill color over 240ms and swaps between the send arrow, spinner, and stop square on the morph spring (0.42s, bounce 0.16).
Under prefers-reduced-motion: reduce, box and tray heights cut immediately while chips and send icons keep short opacity crossfades and press scale is removed. Setting motion="none" makes every transition immediate (0ms).
| Token | Role |
|---|---|
--ui-surface, --ui-surface-raised, --ui-highlight | File card fill, outline box surface, and soft box fill. |
--ui-border, --ui-border-strong, --ui-border-width | Resting border, focused border, and border stroke width. |
--ui-text, --ui-text-secondary, --ui-muted | Input text, file icons, placeholders, and metadata. |
--ui-accent, --ui-accent-foreground, --ui-accent-subtle | Ready send button fill, icon contrast, and drag-over tint. |
--ui-danger, --ui-track, --ui-focus-ring | Failed attachment state, upload progress rail, focus ring. |
An application-wide UtherealProvider supplies theme, recipe, and motion defaults.
Composition
In an agent composition, PromptInput is a leaf component whose text lives at /fields/instance-<id>/value. submitAction fires before the text clears so the host reads the submitted message from state; toolbar, remove, and retry actions pass their itemId. See Building with agents.
{
"type": "PromptInput",
"props": {
"placeholder": "Ask anything",
"submitAction": "send_message",
"stopAction": "stop_reply"
},
"children": []
}