Components

Prompt input

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.

Install

terminal
npx shadcn@latest add @wobko/prompt-input

First time here? Add the registry to components.json first. How to install

Examples

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.

While a reply streams

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.

Slash commands and @mentions

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.

With attachments

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.

API reference

PromptInput

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.

PropTypeDefaultDescription
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 / onValueChangestring-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.
disabledbooleanfalseNothing can be typed or sent; the writing line goes dashed.
allowEmptybooleanfalseAllow an empty message (attachments only).
lockWhileStreamingbooleanfalseMake 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.

PromptInputTextarea

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.

PropTypeDefaultDescription
minRows / maxRowsnumber1 / 8Rows before it grows and the most it grows to.
placeholderstring"what are we making?"
namestring"message"The form field name, so `new FormData(form)` works.

PromptInputSuggestions

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.

PropTypeDefaultDescription
triggerstring-Only open for this trigger character, so `/` and `@` can each have a list.
openboolean-Force it open or shut, for example `open={items.length > 0}`: a listbox without options is not valid.

PromptInputSuggestion

One `role="option"`. Highlighted with a highlighter swipe when active (hover or keyboard).

PropTypeDefaultDescription
onSelect() => void-Runs on click, Enter or Tab. The usual body is `replaceTrigger("/summarize")` from `usePromptInput()`.
disabledboolean-Skipped by the arrow keys.

Accessibility

  • Enter and Shift+Enter behave like every chat box; neither fires while an IME composition is open (`isComposing`, the composition events and the Safari keyCode 229 quirk are all checked).
  • The textarea is named "Message" unless you label it (`aria-label`, `aria-labelledby`, or an `id` for a `<label htmlFor>`): a placeholder is not a name. While a suggestion list is open it exposes `aria-controls` and `aria-activedescendant`; the list is a `listbox` of `option`s with `aria-selected`.
  • The submit button is named 'Send message' and, while busy, 'Stop generating' (and then it is a real `type="button"`). The form is deliberately not `aria-busy` (some screen readers would skip the textarea and the Stop button); it carries `data-status`. If the keyboard is on Stop when the reply ends, the focus moves back to the writing line.
  • Status and errors are yours to announce (a live region in the chat); the composer keeps focus in the textarea after a send.
  • The paper plane's flight is decoration: with reduced motion the animation ends on the plane at rest. Ink on the napkin is 14:1, the placeholder is graphite (5.9:1).

Source

The files the CLI copies into your project.

Loading the source