- Add the registry
- Add prompt-input
Usage
Enter sends the message and Shift+Enter starts a new line, except while an input method is
composing text. On a touch screen, where there's no Shift key to hold, Enter starts a new line and
the submit button sends the message. Set submitShortcut="mod+enter" on PromptInputTextarea to
make Enter start a new line everywhere and Command+Enter or Control+Enter send.
The field clears when the message is sent, and nothing is sent while it's empty. After the submit button sends a message, focus returns to the field for the next one.
PromptInputActions holds the controls below the field. Each one sits at the start of the row, or
at its end with align="end", so a field with controls on both sides has two.
The field's accessible name is "Message" unless a <label>, a FieldLabel,
aria-label or aria-labelledby labels it.
status takes the same values the AI SDK and TanStack AI use for a reply's progress, so you can
pass either library's useChat status straight through: submitted once the message is sent,
streaming while the reply arrives, then ready, or error if it failed. Nothing can be sent
while the status is submitted or streaming.
With onStop, the submit button becomes a stop button while a reply is on its way. It stays
pending while a promise returned by onStop settles. It ignores the second click of a double-click
on the submit button, so sending a message can't immediately stop its reply. Without onStop, the
submit button shows a Spinner until the reply is done. The submit button's
children and aria-label set what it shows and its accessible name while it sends, and
stopIcon and stopLabel set them while it stops.
Return a promise from onSubmit to keep the submit button pending until the promise settles. If it
rejects, the message is restored to the field through onValueChange, unless the person has started
typing a new one.
Composition
Examples
With a model picker
PromptInputButton is a ghost icon Input Group button that's disabled
along with the field. The attach and submit buttons are built on it. A Select
trigger in PromptInputActions drops its background and shadow so it sits flat beside the buttons.
The field shows its hover tint only while the pointer isn't over one of its controls, and its focus ring only while the textarea has focus, so each control keeps its own hover and focus states.
With usage
PromptInputUsage shows how much of the model's context the conversation has used, as a half-circle
Gauge and a percentage. The gauge uses the brand color, then turns to the
warning color at 75% and the destructive color at 90%. It's a meter rather than a button, so
pressing it does nothing. Its Tooltip shows value and max in tokens, and
opens on hover, on focus and on tap on a touch screen. Screen readers announce "Context used" with
the percentage and the counts, such as "64%, 128K of 200K tokens". label changes the tooltip,
aria-label the accessible name, and aria-valuetext the announced value.
With attachments
A Prompt Input accepts files only when it contains PromptInputAttachments. That part lists the
attached files above the text, each with a remove button, and renders nothing while there are none.
With it, files dropped on or pasted into the field are attached, excluding folders, and
PromptInputAttach opens a file picker. Without it, PromptInputAttach is disabled. A paste that
also holds text, such as cells copied from a spreadsheet, pastes the text instead.
Removing a file moves focus to the next file's remove button, or the previous one's, or to the field
once none are left. onSubmit receives the files as files, an array of Files, and a message can
be sent with files and no text. The files and text both clear when the message is sent.
PromptInputAttachments takes accept, maxFiles and maxSize to limit which files are accepted,
as a File Input does. onFileReject is called for each rejected file,
with a PromptInputFileRejectReason. PromptInputAttach is disabled once maxFiles files are
attached. To control the files, use files, defaultFiles and onFilesChange on PromptInput,
the way value controls the text. onFilesChange receives PromptInputFilesChangeEventDetails.
Adaptive layout
With layout="adaptive", the actions sit beside a message that fits on one line, with the start
actions before it and the end actions after it. Once the message wraps or has a line break, it takes
the full width and the actions move below it, as in the stacked layout. Focus moves in the same
order in both: the field, then the start actions, then the end actions.
The field starts at one line in this layout. Setting --prompt-input-min-rows above 1 keeps the
actions below it.
Height
The field grows with the message, then scrolls. Set --prompt-input-min-rows and
--prompt-input-max-rows in PromptInput's className to change how many lines it shows. They
default to 2 and 8, and you can set them per breakpoint. The field never grows past half the
viewport's height, so the actions stay in view above a software keyboard.
With a character limit
submitDisabled stops Enter and the submit button from sending the message, but leaves the field
editable. Use it for a rule your app checks, such as a length limit or files that are still
uploading. disabled disables the field too.
Custom controls
usePromptInput reads the Prompt Input that your component renders in, so a
control of your own can read and change the message. This
Dropdown Menu fills the field with a template.
Disabled
disabled disables the field and every PromptInputButton in it, including the submit button, and
removes them from the tab order. The whole field dims once, so its controls don't dim any further.
Props
PromptInput renders a <form>, which render replaces. It leaves out the form's action,
method, encType and target, since it passes the message to onSubmit rather than submitting
the form. Enter and the submit button send the message by submitting that form, so render has to
render a form too, and a Prompt Input can't sit inside another form.
Base UI's styling (opens in a new tab) and composition (opens in a new tab) guides say more about className, style and render.
PromptInput
PromptInputAttachments
PromptInputTextarea
PromptInputActions
PromptInputButton
PromptInputAttach
PromptInputSubmit
PromptInputUsage
usePromptInput
usePromptInput() reads the PromptInput that your component renders in, and returns its state: