Prompt Input
ProThe message box of a chat or an agent: a growing text field with attach, optional tools and a model chip, and a Send button that becomes Stop.
Playground
Installation
Prompt Input comes with WunderUI Core and Pro, in the package from your plan. See the plans.
Then import what you need:
import { PromptInput, ModelCompareMenu, PromptProjects } from "@wunderui/react"Then use it:
import { useState } from "react"
import { PromptInput } from "@wunderui/react"
export function Composer() {
const [value, setValue] = useState("")
return (
<PromptInput
value={value}
onValueChange={setValue}
onSubmit={() => {
// send `value` to your model, then clear the box
setValue("")
}}
/>
)
}Expected result: You should see a bordered box with the placeholder Ask anything..., an attach button and a dimmed round Send button. Type a word and Send turns solid; press Enter and the box empties.
When to use
Use Prompt Input for
- The message box of a chat, an assistant or an agent where the user writes a prompt and sends it
- A prompt that may run over several lines, with attachments, tools or a choice of model
- A turn that can be stopped while the reply is generated
Use something else for
- Textarea for a multi-line field in a form, with no send button
- Input for a short single-line value such as a search term or a name
- Rich Text Editor for formatted documents; a chat composer never gets a formatting toolbar
Toolbar
The row under the text holds Attach files, your tools and the model chip on the left, and the round Send button on the right. Attach can be hidden; the chip appears only when you pass models.
State
Send turns off when the field is empty or a reply is generating, and a stop handler swaps it for Stop. The field stays editable meanwhile; Disabled dims the whole box to 40 % and sends nothing.
Text length
The field starts at one line and grows with the text up to 160 px. Beyond that the text scrolls inside the field and the toolbar stays put.
Attachments and chips
The `attachments` slot is a row above the field for Chat Attachment items, with remove; it wraps onto more lines and never clips. The `chips` slot sits in the footer after the tools and the model chip: a Model Compare Menu ("4 models"), tags as Record Chip with a remove button. The icons of the toolbar are grey at rest and black on hover, focus and when pressed.
Keyboard interactions
The field is a native textarea and the controls are native buttons, so the browser provides typing, focus and activation.
- Enter
- Sends. It calls when the text is not empty and no reply is generating, and does nothing otherwise. The Enter that confirms an IME composition is not a send.
- Shift+Enter
- Adds a new line. The field grows with it.
- TaborShift+Tab
- Moves focus through the field, Attach files, your tools, the model chip and Send or Stop, in that order. Send stays a tab stop while it is , so its tooltip can be read.
- EnterorSpace
- Presses the focused button: attaches, runs a tool, opens the model list, sends or stops.
- Escape
- Closes the model popover and returns focus to the chip.
Every control is a tab stop and the box has no arrow-key navigation of its own (the model list has its own). Escape closes the model popover, and when disabled nothing in the box takes focus.
Behavior and motion
What the box does with the text, the send keys, the reply state and the focus.
- Controlled text
- The value and its change handler are required. The box keeps no text of its own, so clear the field in the submit handler after you have read the value.
- When Send works
- Send, by key or by click, only works when the trimmed text is not empty and no reply is generating. Spaces alone count as empty.
- Send keys
- Enter sends and Shift+Enter adds a line. An Enter pressed while an IME composition is open confirms the composition instead, so Japanese, Chinese and Korean input work.
- Send that is not ready
- While Send is not ready it is aria-disabled, so it stays in the tab order, is dimmed to 40 % and shows a tooltip: Type a message first, or Wait for the reply to finish.
- Generating
- Set loading while the reply runs; with a stop handler, Send is replaced by a Stop button. The field stays editable so the next prompt can be written, but it is not sent until loading ends.
- Disabled
- Disabled turns the whole box off: the field and all buttons are dimmed to 40 % and out of the tab order, and nothing can be sent. Buttons in the tools slot are yours to disable.
- Growth
- The field is one line at rest and grows with its content up to 160 px, then scrolls. The height is set directly and is not animated.
- Names
- The placeholder is not a name: the field is named by its aria-label, Message by default. The buttons are named Attach files, Send, Stop generating and Model followed by the name.
- Attachments
- The box holds no files. The paperclip only calls the attach handler; keep the files in your state and show them with Chat Attachment above the field.
- Focus
- The box draws the focus ring (indigo border and 2 px ring) while the text field has focus. Each button inside draws its own ring when it takes keyboard focus.
- Motion
- The box changes its border and background with a quick colour transition. The model chevron turns 180 degrees when the list opens.
- Reduced motion
- No motion carries meaning here. The growth and the swap from Send to Stop are instant, so reduced motion changes nothing.
- While a request is blocked
- Disable the box when the person cannot write at all, such as a closed conversation, a used-up quota or an approval pending. Use loading while a reply is generated, so the next prompt can be written.
Anatomy
The figure marks the box, the field and the controls of the toolbar. The tools slot, the model chip, the attachments row and the chips row appear only when you pass them.
- 1data-slot="prompt-input"
A 16 px bordered box with 12 px padding that holds the field and the toolbar. It draws the focus ring while the text field has focus and looks dimmed when disabled.
- 2
A textarea named by an aria-label, Message by default. It starts at one line, grows to 160 px, then scrolls, and is dimmed to 40 % when disabled.
- 3Optional
An icon button named Attach files that only calls the attach handler; opening the file picker is yours. You can hide it, and disabling the box turns it off.
- 4data-slot="prompt-input-tools"Optional
A slot after the attach button for your own icon buttons, such as web search or a link. Give each one an aria-label. The attach button and your tools sit in this slot: their icons are grey at rest and black on hover, focus and when pressed. A button with keeps its own colour.
- 5Optional
A Model Picker pill that opens a popover with the models. It exists only when you pass models and is named Model followed by the current name.
- 6
A round primary icon button named Send, aria-disabled while the text is empty or a reply is generating. With loading and a stop handler it becomes the Stop generating button.
- data-slot="prompt-input-mentions"Optional
- data-slot="prompt-input-mention"Optional
- data-slot="prompt-input-suggestion"Optional
- data-slot="prompt-input-attachments"Optional
A wrapping row above the text field for Chat Attachment items, shown when you pass .
- data-slot="prompt-input-chips"Optional
A wrapping row in the footer after the tools and the model chip for a Model Compare Menu or removable Record Chip tags, shown when you pass .
Best practices
- Do
Send in the submit handler and clear the value there. The component skips an empty prompt and a send while generating, so you need no second check.
- Do
While a reply runs, pass loading and a stop handler together, so the person can always stop it. Without the stop handler, Send only turns off.
- Do
When more than one box is on a screen, set an aria-label that names the conversation, such as Message to the planner.
- Do
Disable the box when writing is not possible, such as a closed conversation or an exhausted quota, and say why next to it. While a reply is generated, use loading, not disabled.
- Do
Give every icon button in the tools slot an aria-label. An icon alone is not a name.
- Don’t
Don't build a composer with a rich text toolbar (bold, italic, underline). A prompt is plain text; formatting belongs in the reply, not in the box.
- Don’t
Don't send on blur or on every change. Sending is the person's decision: Enter or the Send button.
- Don’t
Don't use disabled to show that a reply is generating. The person could not write the next prompt meanwhile; use loading with a stop handler instead.
- Do
Show an example prompt with suggestion (Tab takes it) and mentions with the mentions prop instead of capturing keys around the box; use onKeyDown and textareaProps for anything else.
API reference
PromptInput is a plain component, not a wrapper of a primitive. It takes the props below and no other element attributes.
A 16 px bordered box with 12 px padding that holds the field and the toolbar. It draws the focus ring while the text field has focus and looks dimmed when disabled.
| Prop | Type | Default | Description |
|---|---|---|---|
| value required | string | — | The text of the field. The box is controlled, so keep it in state. |
| onValueChange required | (value) => void | — | Called with the new text on every change, including the new lines added with Shift+Enter. |
| onSubmit | () => void | — | Called by Enter and by the Send button when the text is not empty and no reply is generating. Read here, then clear it. |
| placeholder | string | "Ask anything..." | The hint shown while the field is empty. It is not the accessible name. |
| aria-label | string | — | The accessible name of the text field, by default. Set one that fits the screen. |
| loading | boolean | — | A reply is being generated. Enter and Send do not send; with the Send button is replaced by Stop. |
| onStop | () => void | — | Called by the Stop button. It shows only while is true. Abort the request here and set to false. |
| attach | boolean | true | Set to false to hide the Attach files button. |
| disabled | boolean | false | Turns the whole box off: the field, Attach files, the model chip and Send or Stop. Nothing is sent. Buttons in are not affected. |
| onAttach | () => void | — | Called by the Attach files button. Open your file picker here; the box does not read or show files. |
| tools | ReactNode | — | Extra buttons after Attach files, such as web search or a link. Use icon buttons with an . |
| attachments | ReactNode | — | A row above the text field for Chat Attachment items (each with its own remove button). It wraps onto more lines and never clips. Nothing renders when it is empty. |
| chips | ReactNode | — | Chips in the footer after the tools and the model chip: a Model Compare Menu ("4 models") or removable tags (Record Chip with ). They wrap below the tools on narrow boxes. |
| models | ModelOption[] | — | The models of the chip: each has an and a , and optionally a , a and an . The chip is shown only when the list is not empty. |
| model | string | — | The id of the chosen model, for a controlled chip. |
| defaultModel | string | — | The id of the model the chip starts on when you do not control it. Without it the first model is used. |
| onModelChange | (id) => void | — | Called with the id of the model the person picks. |
| className | string | — | Extra classes for the box, for example to set its width. |
| mentions | PromptMentions | — | Mentions: typing the trigger ("@") lists the items above the box (below it, or scrolling, where the space above is too small); ↑ ↓ move, Enter or Tab pick, Esc closes. |
| onKeyDown | KeyboardEventHandler<HTMLTextAreaElement> | — | Keys on the text field, before the box handles them (Enter sends, Tab takes the suggestion, the mention keys). Call to stop the built-in handling of that key. |
| onSuggestionAccept | (text) => void | — | Called after Tab took the suggestion over. |
| suggestion | string | — | A suggested prompt as ghost text: in an empty box (in place of the placeholder), or as the rest of what was typed while the suggestion starts with it. Tab takes it over. |
| textareaProps | Omit<ComponentProps<"textarea">, "value" | "defaultValue" | "onChange" | "disabled"> | — | Extra props for the text field (, , , , …); , and stay with the box. |
| Prop | Type | Default | Description |
|---|---|---|---|
| models required | ModelOption[] | — | |
| onValueChange required | (ids) => void | — | |
| value required | string[] | — | |
| disabled | boolean | false | |
| label | string | "Answer with" | |
| primaryHint | string | "The chat"s model, always answers" |
| Prop | Type | Default | Description |
|---|---|---|---|
| projects required | PromptProject[] | — | |
| aria-label | string | — | Accessible name of the group (required when no labelledBy). |
| aria-labelledby | string | — | |
| clearable | boolean | true | Clicking the chosen card again clears the choice. Default true. |
| defaultValue | string | null | — | |
| onValueChange | (id) => void | — | |
| value | string | null | — |
Notes for AI
Give your coding assistant the Markdown reference instead of screenshots.
get_component("prompt-input")The full library index for assistants is at /llms.txt.
Related components
Commands
/summarizeSummarize the open thread/explainExplain the selected code/testWrite tests for the open file/translateTranslate the last reply/docsSearch the WunderUI docs↑↓ to move · ↵ to run · esc to close
AI & Agents4 stylesProSlash Command MenuThe popover that opens when someone types / in the prompt: commands with a short description, filtered as they type.