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.
Pick a model and dictate
Put the message's controls in PromptInput.Footer. For a model picker, use Select with a name, so the form submits the model with the message. Mantle has no model picker component, because each app lists its own models.
PromptInput.Dictate turns speech into text with the browser's speech recognition. Each final phrase replaces the field's selection and runs your onChange. The browser supplies spacing; maxLength limits the edit. Disabled and read-only fields stay unchanged.
Press the toggle again to stop. If recognition fails or ends, press it to start a new session. Dictation does not send the message. Its edits do not enter the browser's undo history, so review a selected passage before you replace it.
The toggle renders nothing on the server and in browsers without speech recognition, and appears after hydration where the browser has it. Keep it before PromptInput.Submit, so the send button does not move when it appears.
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. PromptInput.Dictate owns its button so that it can report the listening state with aria-pressed.
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.Dictate
A toggle that turns speech into text in PromptInput.TextArea. It reports aria-pressed while it listens. It renders nothing on the server and in browsers without speech recognition.
Each final phrase replaces the selection with the browser's text, including its spacing, up to maxLength. Dictation skips disabled and read-only fields. An error or the end of a session resets the toggle. Disabling the toggle ends the session. Dictated edits do not enter the browser's undo history.
All props from Icon Button except appearance, aria-pressed, 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: