Skip to main content

Prompt Input

Preview

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.

Desktop viewport
Tablet viewport
Mobile viewport

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.

Desktop viewport
Tablet viewport
Mobile viewport

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.

Desktop viewport
Tablet viewport
Mobile viewport

Composition

PromptInput.Root├── PromptInput.TextArea└── PromptInput.Footer    ├── PromptInput.AttachButton    └── PromptInput.Submit

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 streaming is 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:

PropTypeDefaultDescription
streaming?booleanfalseTrue while an answer streams. PromptInput.Submit then stops the answer, and Enter does not submit.
onStop?() => voidRuns when the person presses stop. Required when you set streaming.
onFilesAdd?(files: File[]) => voidReceives the files a person attaches: from PromptInput.AttachButton, a drop on the frame, or a paste into the field.
asChild?booleanfalseRender as a different element by passing a child, such as your router's form.
Data AttributeValueDescription
data-slot"prompt-input"On the form, joined with ancestor slots.
data-streamingpresent while streamingPresence-only. Style with data-streaming:.
data-drag-overpresent while files drag over the framePresence-only. Set only with onFilesAdd.

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.

PropTypeDefaultDescription
rows?number2The height in lines, in browsers that do not support field-sizing.
Data AttributeValueDescription
data-slot"prompt-input-text-area text-area"On the field, joined with ancestor slots.
data-drag-overpresent during a dragInherited from TextArea.
data-validation"error" | "success" | "warning"Validation from an enclosing Field.

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:

PropTypeDefaultDescription
asChild?booleanfalseRender as a different element by passing a child.
Data AttributeValueDescription
data-slot"prompt-input-footer"On the row, joined with ancestor slots.

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:

PropTypeDefaultDescription
accept?stringThe file types the picker offers, such as "image/*,.txt". A drop or a paste is not filtered.
label?string"Attach files"The accessible name of the button.
Data AttributeValueDescription
data-slot"prompt-input-attach-button icon-button"On the button, joined with ancestor slots.
data-icon-button"true"Inherited from IconButton.
data-appearance"ghost"The button's appearance.
data-intent"neutral"The button's tone.
data-size"2xs" | "xs" | "sm" | "md" | "lg" | "xl"The size prop; defaults to "sm".
data-loadingpresent when isLoadingInherited from IconButton.

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:

PropTypeDefaultDescription
label?string"Send message"The accessible name of the button while it sends.
stopLabel?string"Stop answer"The accessible name of the button while it stops.
Data AttributeValueDescription
data-slot"prompt-input-submit icon-button"On the button, joined with ancestor slots.
data-icon-button"true"Inherited from IconButton.
data-appearance"filled"The button's appearance.
data-intent"neutral"The button's tone.
data-size"sm"The button's size, fixed so it fits the footer.
data-loadingpresent when isLoadingInherited from IconButton.