Skip to content

Molecules · Prompt input

Prompt input

The box where a person writes to an assistant. It grows to fit the text, has one Send/Stop button and can show suggestions. Enter sends, and Shift+Enter starts a new line.

Best for
The message box under a ChatThread.
Not for
A long field in a form: use Textarea inside a FormField.

This page as Markdown, a plain-text copy for a coding agent (an AI tool that writes code).

Requires

  • A parent that keeps the draft in state and clears it in onSubmit.

Examples

With suggestions

Enter to send, Shift+Enter for a new line

Nothing sent yet.

Code
tsx
function DraftExample() {  const [value, setValue] = useState('')  const [sent, setSent] = useState<string | null>(null)  return (    <div className="flex w-full max-w-xl flex-col gap-3">      <PromptInput        label="Message the assistant"        placeholder="Ask about stock, orders or depots"        value={value}        onValueChange={setValue}        onSubmit={text => {          setSent(text)          setValue('')        }}        suggestions={['Summarise stock at Depot 4', 'Which replicas are running low?']}      />      <p className="font-body text-sm text-[var(--color-text-secondary)]" aria-live="polite">        {sent === null ? 'Nothing sent yet.' : `Sent: ${sent}`}      </p>    </div>  )}​<DraftExample />

Busy: a Stop button takes the place of Send, and pressing Escape stops it too

Enter to send, Shift+Enter for a new line

Code
tsx
function BusyExample() {  const [value, setValue] = useState('')  const [busy, setBusy] = useState(true)  return (    <div className="flex w-full max-w-xl flex-col gap-3">      <PromptInput        label="Message the assistant, while it works"        value={value}        onValueChange={setValue}        onSubmit={() => setValue('')}        busy={busy}        onStop={() => setBusy(false)}      />      {busy ? null : (        <Button size="sm" variant="ghost" wrapperClassName="self-start" onClick={() => setBusy(true)}>          Make it busy again        </Button>      )}    </div>  )}​<BusyExample />

Disabled

Enter to send, Shift+Enter for a new line

The assistant is offline until 14:00.

Code
tsx
<div className="flex w-full max-w-xl flex-col gap-2">  <PromptInput label="Message the assistant (disabled)" value="" onValueChange={() => {}} onSubmit={() => {}} disabled />  <p className="font-body text-sm text-[var(--color-text-secondary)]">The assistant is offline until 14:00.</p></div>

Anatomy

PartWhat it is
FormPaints surface.base itself, as every form does.
SuggestionsA group of chips above the box. Clicking one submits its text (disabled while busy), or with editableSuggestions puts it in the box to edit.
BoxA Textarea with a label that's hidden on screen but read by screen readers. It grows from one line to about eight, then scrolls inside.
Send / StopOne button: a primary Send with an arrow, or, while busy, a secondary Stop with a square.
HintOne line under the box, which is also the box's description: "Enter to send, Shift+Enter for a new line".

Props

labelstring
Required. Names the box. It's hidden on screen.
valuestring
Required. The draft. Controlled, meaning your page holds it.
onValueChange(value: string) => void
Required.
onSubmit(value: string) => void
Required. Fires on Enter, Send or a suggestion, and never with a blank draft. Clear the draft here.
busybooleanDefault false
Send turns into Stop, and Enter sends nothing.
onStop() => void
Runs on Stop, and on Escape in the box while busy.
suggestionsreadonly string[]
Ready-made prompts shown as chips. Clicking one submits it.
editableSuggestionsbooleanDefault false
Clicking a suggestion puts its text in the box to edit instead of sending it. Use it when a person will likely change the prompt first. The chips then stay usable while busy.
placeholderstring
Shown in the empty box.
disabledbooleanDefault false
Nothing can be typed or sent. Say why somewhere nearby.
hintstringDefault 'Enter to send, Shift+Enter for a new line'
The line under the box, which is also its description.
classNamestring
Added to the form.

Keyboard

KeysResult
EnterSends the draft. Does nothing while busy, or while someone's composing characters with an IME (Input Method Editor, the tool used to type languages like Chinese or Japanese).
ShiftEnterStarts a new line.
EscapeWhile busy, stops the reply.

Do and don't

Do

  • Clear the draft in onSubmit, and set busy as soon as the request starts.
  • Wire up onStop whenever the reply can be stopped. A reply that streams in with no Stop is a wait with no way out.
  • Offer two to four suggestions in an empty thread, and drop them once the conversation has started.

Don't

  • Don't disable the box while busy; a person may be writing the next message while the reply arrives.
  • Don't wrap it in a FormField. Its label is hidden on purpose, and it brings its own hint.
  • Don't move focus into it when the reply finishes. It never left, unless the person moved it.

Wrong

tsx
{busy ? <Button onClick={stop}>Stop</Button> : <Button type="submit">Send</Button>}

Right

tsx
<PromptInput busy={busy} onStop={stop} ... />

Swapping two buttons drops keyboard focus to the page at the moment they switch. PromptInput keeps one button and changes its label and what it does.