The composer
Type, press Enter and the paper plane flies. Shift+Enter breaks the line; the box grows with the text up to eight rows. The send button is pencilled in until there is something to send.
The composer of a chat: a napkin strip with a writing line, an auto-growing textarea, room for attachments and a paper-plane send button that flies off when the message goes. Enter sends, Shift+Enter breaks the line, IME composition is left alone, and while a reply streams the button becomes a stop button. Slots for slash commands and @mentions, with no data of their own.
npx shadcn@latest add @wobko/prompt-input第一次使用?先把 registry 加进 components.json。 如何安装
Type, press Enter and the paper plane flies. Shift+Enter breaks the line; the box grows with the text up to eight rows. The send button is pencilled in until there is something to send.
With status streaming the send button is a stop button and sending waits; you can keep typing the next message. `lockWhileStreaming` makes the text read-only instead.
The composer knows no data. `triggers` says which characters open a list, `usePromptInput().trigger` gives the word being typed, and you render the choices. Arrows move, Enter or Tab pick, Escape closes.
Chips in the row above the text, a file button in the tools, a send that also works with no words when `allowEmpty` is set. Pick a file to add a chip; the remove button takes it away again.
The form and the state: text (controlled or not), status, submit, stop, and the trigger word under the caret. It is a `Paper` (default stock `napkin`, crimped edge), so any Paper prop works.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| onSubmit | (value: string, event: FormEvent) => void | - | Called on Enter (or Ctrl/Cmd+Enter) and on the submit button. Not called when the text is empty, the chat is busy or the composer is disabled. |
| value / defaultValue / onValueChange | string | - | Controlled or uncontrolled text. An uncontrolled composer clears after a send (`clearOnSubmit`); a controlled one clears itself in `onSubmit`. |
| status | "ready" | "submitted" | "streaming" | "error" | "ready" | `submitted` and `streaming` turn the send button into a stop button and block sending. Matches the status of common chat hooks. |
| onStop | () => void | - | Called by the stop button. |
| disabled | boolean | false | Nothing can be typed or sent; the writing line goes dashed. |
| allowEmpty | boolean | false | Allow an empty message (attachments only). |
| lockWhileStreaming | boolean | false | Make the text read-only while the reply streams. By default you can type the next message; sending waits. |
| submitOn | "enter" | "mod-enter" | "enter" | `mod-enter` sends on Ctrl/Cmd+Enter and Enter is a new line. |
| triggers | (string | { char: string; atStart?: boolean })[] | - | Characters that open a suggestion list at the start of a word: `"@"`, or `{ char: "/", atStart: true }` for commands only at the start of the message. |
| onTriggerChange | (trigger | null) => void | - | Called when the word under the caret starts or stops being a trigger word. |
The textarea, set in the script font in blue felt (your hand). It grows with its text (`field-sizing`, with a script fallback for Firefox) up to `maxRows`, then scrolls. It carries `aria-controls` and `aria-activedescendant` while a suggestion list is open.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| minRows / maxRows | number | 1 / 8 | Rows before it grows and the most it grows to. |
| placeholder | string | "what are we making?" | |
| name | string | "message" | The form field name, so `new FormData(form)` works. |
A slip above the composer, open while the caret is in a trigger word. A `role="listbox"`; it takes no focus (the caret stays in the textarea) and is driven from the textarea: Arrow keys move, Enter or Tab pick, Escape closes it for that word.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| trigger | string | - | Only open for this trigger character, so `/` and `@` can each have a list. |
| open | boolean | - | Force it open or shut, for example `open={items.length > 0}`: a listbox without options is not valid. |
One `role="option"`. Highlighted with a highlighter swipe when active (hover or keyboard).
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| onSelect | () => void | - | Runs on click, Enter or Tab. The usual body is `replaceTrigger("/summarize")` from `usePromptInput()`. |
| disabled | boolean | - | Skipped by the arrow keys. |
CLI 会复制进你项目的文件。
正在加载源码