GooseUI

Components

Prompt Input

New

The message box of a chat with an AI assistant. The textarea grows with the text up to a maximum height, Enter sends and Shift+Enter adds a line (or Ctrl/⌘+Enter sends, if you prefer). Files are attached with the paperclip, by drag and drop or by pasting a screenshot. While a reply streams, the send button becomes a stop button. Parts are composable: put your own model picker or toggles into the toolbar.

Browser Support

Baseline Newly available
2 features
Details
field-sizing

The textarea grows with its text up to max-height. Without it a small script sets the height from scrollHeight on every change.

Your browser:
:has()

Draws the focus ring around the whole box when the textarea has keyboard focus, and the red border when the text is over maxLength. Without it the border still changes colour through :focus-within, and the counter turns red.

Your browser:

Preview

Hi! Ask me anything about your frontend. You can attach screenshots by pasting or dropping them here.
0 / 2000 characters

Installation

npx shadcn@latest add @gooseui/prompt-input
pnpm dlx shadcn@latest add @gooseui/prompt-input
yarn dlx shadcn@latest add @gooseui/prompt-input
bunx --bun shadcn@latest add @gooseui/prompt-input

Usage

"use client"

import { useRef, useState } from "react"
import {
  PromptInput,
  PromptInputAttachButton,
  PromptInputAttachments,
  PromptInputCounter,
  type PromptInputStatus,
  PromptInputSubmit,
  PromptInputTextarea,
  PromptInputToolbar,
} from "@/components/ui/prompt-input"

export function Composer() {
  const [status, setStatus] = useState<PromptInputStatus>("idle")
  const controller = useRef<AbortController | null>(null)

  return (
    <PromptInput
      status={status}
      maxLength={2000}
      onStop={() => controller.current?.abort()}
      onSubmit={async ({ text, files }) => {
        controller.current = new AbortController()
        setStatus("streaming")
        try {
          await sendToModel(text, files, controller.current.signal)
        } finally {
          setStatus("idle")
        }
      }}
    >
      <PromptInputAttachments />
      <PromptInputTextarea />
      <PromptInputToolbar>
        <PromptInputAttachButton />
        <PromptInputCounter className="ml-auto" />
        <PromptInputSubmit />
      </PromptInputToolbar>
    </PromptInput>
  )
}

Examples

Compact reply

The same parts in one row: className on PromptInput turns the column into a wrapping row, and the attachments take a full line above it.

  • Priya: Can we move the design review to Thursday?
<PromptInput
  onSubmit={({ text }) => reply(text)}
  placeholder="Reply to Priya"
  className="flex-row flex-wrap items-end gap-1 rounded-3xl p-1"
>
  <PromptInputAttachments className="basis-full" />
  <PromptInputAttachButton />
  <PromptInputTextarea className="max-h-32 min-h-8 min-w-0 flex-1 basis-0 px-1 py-1.5" />
  <PromptInputSubmit />
</PromptInput>

Feedback with Ctrl/⌘ + Enter

submitOn="mod+enter" leaves Enter for new lines. Above maxLength the counter turns red and sending is blocked.

Ctrl/⌘ + Enter to send0 / 280 characters
<PromptInput
  submitOn="mod+enter"
  maxLength={280}
  placeholder="What should we improve in the checkout flow?"
  onSubmit={({ text }) => sendFeedback(text)}
>
  <PromptInputTextarea className="min-h-20" />
  <PromptInputToolbar>
    <span className="text-muted-foreground text-xs">Ctrl/⌘ + Enter to send</span>
    <PromptInputCounter className="ml-auto" />
    <PromptInputSubmit />
  </PromptInputToolbar>
</PromptInput>

Default layout

Without children PromptInput renders the attachments, the textarea and a toolbar with the attach button, the counter and send. accept limits the picker, drop and paste to images and PDF.

<PromptInput
  accept="image/*,.pdf"
  placeholder="Describe the bug, attach a screenshot or PDF"
  onSubmit={({ text, files }) => createIssue(text, files)}
/>

Props

PropTypeDefaultDescription
valuestring-Controlled text
defaultValuestring""Initial text when uncontrolled
onValueChange(value: string) => void-Called on every change of the text
onSubmit(message: { text: string; files: File[] }) => void-Called with the trimmed text and the attached files. The field is cleared afterwards
status"idle" | "submitting" | "streaming""idle"submitting shows a spinner, streaming turns the send button into stop. Both block sending
onStop() => void-Called by the stop button while streaming
placeholderstring"Send a message…"Placeholder of the textarea
maxLengthnumber-Soft limit: the counter turns red and sending is blocked above it, the text itself is not cut
submitOn"enter" | "mod+enter""enter"Which shortcut sends. With enter, Shift+Enter adds a new line
acceptstring-File types for the picker, drop and paste, as in the accept attribute
maxFilesnumber10Maximum number of attachments
disabledbooleanfalseDisables the whole box
labelsPartial<PromptInputLabels>EnglishTexts for screen readers and the drop overlay
classNamestring-Additional CSS classes for the form

Components

ComponentDescription
PromptInputThe form and its state. Without children renders the default layout
PromptInputTextareaGrowing textarea. Handles Enter, IME composition and pasted files
PromptInputAttachmentsChips of attached files with image previews
PromptInputToolbarRow for buttons and your own controls. Server component
PromptInputAttachButtonPaperclip button that opens the file picker
PromptInputCounter“12 / 500” counter, only with maxLength
PromptInputSubmitSend button, spinner while submitting, stop while streaming
usePromptInput()State and actions for your own parts: text, attachments, submit…

Features

  • IME safe. Enter that confirms a Chinese or Japanese composition does not send the message.
  • Paste and drop. A pasted screenshot becomes an attachment; when the clipboard also has text, the text is kept. Dropping is handled by useFileDrop.
  • Server parts. PromptInput with its default layout and the toolbar are server components; state, keys and files live in prompt-input.client.