The message box of a chat, with a field that grows with its text and one button that sends or stops. PromptInput.Root is a native <form>, so you read the message in onSubmit or action.
When to use
- Let a person write a message to an assistant or a model and send it with Enter.
- Let them stop an answer while it streams, with the same button.
- Prefer Text Area for free-form text that a form submits with its other fields.
- Prefer Input for a single-line field, such as a search box.
Stop a streaming answer
Set streaming on PromptInput.Root while an answer streams, and pass onStop. PromptInput.Submit then stops the answer. It stays the same button, so focus does not move when the answer starts or ends. The field stays editable, so the person can write the next message, but Enter does not submit until the answer ends.
Attach files
Set onFilesAdd on PromptInput.Root to take files. A person can pick them with PromptInput.AttachButton, drop them on the frame, or paste them into the field. Show them with Attachment above the field. Reading, checking, and storing the files stays with your app.
Composition
Polymorphism
PromptInput.Root and PromptInput.Footer take asChild. Use it on PromptInput.Root to render your router's form component, such as React Router's <Form>, in place of the native <form>.
PromptInput.TextArea keeps its native <textarea> because its Enter handler depends on the field's form owner and editing behavior.
PromptInput.Submit does not take asChild. It owns its button so that it can change from send to stop and keep focus.
Keyboard
- Enter submits the form.
- Shift+Enter adds a line.
- On a touch screen, Return adds a line, because on-screen keyboards have no Shift+Return. The person sends with
PromptInput.Submit. - The Enter that confirms an input method editor (IME) candidate does not submit. This includes Safari, which ends the composition before the key event.
- Enter does nothing while
streamingis set, or when the form's default button is disabled. The second rule matches the implicit submission of the HTML Standard.
Enter activates the form's first submit button, including its click handler and submission overrides. If the form has no submit button, Enter calls requestSubmit().
PromptInput.Submit is never disabled for an empty field, because a gray button reads as a broken message box. Ignore a blank message in your submit handler, as the examples do.
API Reference
PromptInput.Root
The message box: a native <form> that holds the field and its controls in one frame. The frame draws the focus ring when a control inside it has focus.
All props from form, plus:
PromptInput.TextArea
The message field. It grows with its text up to max-h-48, then scrolls. Name it with aria-label or a Label.
For a form action, set name="message" on the field and read formData.get("message") in the action. The accessible name does not set the form-data key.
All props from Text Area except appearance and validation.
PromptInput.Footer
The row under the field for the message's controls, such as a model picker, an attach button, and PromptInput.Submit.
All props from div, plus:
PromptInput.AttachButton
The button that opens the file picker. It needs onFilesAdd on PromptInput.Root.
All props from Icon Button except appearance, asChild, children, icon, intent, label, and type, plus:
PromptInput.Submit
The button that sends the message, and stops the answer while one streams. It sits at the end of PromptInput.Footer.
All props from Icon Button except appearance, asChild, children, icon, intent, label, size, and type, plus: