# PromptBox

Where a person writes to an AI agent: a field that grows with the message (rows, default 1, to maxRows, default 10, then scrolls), Send at its end and Stop in the same place while a reply streams (streaming, onStop), and a lower row for attach and the app's actions (a mode or model picker, a tool toggle). Enter sends the trimmed message to onSubmit and clears the draft, Shift+Enter starts a new line, an Enter that picks a word being composed (Japanese, Chinese, Korean input) never sends, and on a touch screen Enter starts a line and Send sends; focus stays in the field after sending and after Stop. label names the field for screen readers and is the placeholder unless placeholder is given. Files: with onAttach the box shows an attach button and takes pasted files (a copy from a document stays text) and files dropped on it; files outside accept or over maxSize are refused with the reason; attachments (FileUpload's items: name, size, status, progress, error) show as chips above the field with Remove (onRemoveAttachment), and Send waits while one uploads. maxLength counts near the limit and past it, and Send waits; unavailable says why nothing can be sent now under the box (offline) while people can still write; error says what went wrong, announced, and the message that failed returns to the empty field. Controlled (value, onValueChange) or not (defaultValue); the ref is the textarea. Every string is a prop (sendLabel, stopLabel "Stop the reply", attachLabel, keyHint, dropLabel, attachmentsLabel, removeLabel, rejectLabel, failedLabel, progressLabel, addedLabel, removedLabel, uploadingLabel, formatCount, formatRemaining). Never inside another form: it is one.

Page: https://turtlekit.dev/components/prompt-box

## Import

```tsx
import { PromptBox } from "turtlekit";
```

## Props

### PromptBox

| Prop | Type | Default | What it does |
| --- | --- | --- | --- |
| `label` (required) | `string` |  | What the field is, for screen readers: "Your message". |
| `placeholder` | `string` |  | The words in the empty field. |
| `value` | `string` |  | The draft, when the app keeps it (clear it in `onSubmit`). |
| `defaultValue` | `string` | `` | The first draft, when the box keeps it itself. |
| `onValueChange` | `(value: string) => void` |  |  |
| `onSubmit` (required) | `(message: string) => void` |  | Send: called with the message (trimmed) on Enter or the send button, when there is something to send; the box then clears the draft (through `onValueChange` when the app keeps it). |
| `streaming` | `boolean` | `false` | True from sending until the reply ends: Stop replaces Send, and Enter sends nothing (people can still type). |
| `onStop` | `() => void` |  | Stop the reply: what arrived stays in the conversation. |
| `attachments` | `ReadonlyArray<PromptBoxAttachment>` | `[]` | The attached files, as chips above the field: their name, size, upload progress, error and a remove button. |
| `onAttach` | `(files: File[]) => void` |  | New files people picked, pasted or dropped that pass `accept` and `maxSize`: upload them and add them to `attachments`. |
| `onRemoveAttachment` | `(id: string) => void` |  | Remove an attached file (and cancel its upload). |
| `accept` | `string` |  | Allowed types, as for an input ("image/*,application/pdf" or ".pdf,.png"). |
| `maxSize` | `number` |  | Largest allowed size in bytes. |
| `actions` | `ReactNode` |  | Controls at the start of the box's lower row, after attach: a mode or model picker, a tool toggle. |
| `maxLength` | `number` |  | The longest message that can be sent. |
| `unavailable` | `string` |  | Why nothing can be sent now, in a sentence ("You're offline. |
| `error` | `ReactNode` |  | What went wrong with the last send and what to do, shown under the box and announced. |
| `disabled` | `boolean` | `false` |  |
| `rows` | `number` | `1` | Lines it shows when empty; it grows with what is typed from there. |
| `maxRows` | `number` | `10` | The most lines it grows to; past them it scrolls inside. |
| `name` | `string` |  | The field's name in a form's data. |
| `sendLabel` | `string` | `Send message` | The send button's name. |
| `stopLabel` | `string` | `Stop the reply` | The stop button's name. |
| `attachLabel` | `string` | `Attach files` | The attach button's name. |
| `keyHint` | `string` | `Enter sends. Shift+Enter starts a new line.` | What screen readers hear about the keys. |
| `dropLabel` | `string` | `Drop files to attach` | Shown over the box while files are dragged over it. |
| `attachmentsLabel` | `string` | `Attached files` | The attachments list's name. |
| `removeLabel` | `(name: string) => string` | `(file) => `Remove ${file}`` | A remove button's name: (name) => `Remove ${name}`. |
| `rejectLabel` | `(name: string, reason: "type" \| "size", limit: string) => string` |  | A refused file's message, with what to do: (name, reason, limit) with reason "type" or "size" and the largest size in words ("20 MB"). |
| `failedLabel` | `string` | `Couldn't upload. Remove it and attach it again.` | A failed upload's line on its chip. |
| `progressLabel` | `(name: string) => string` | `(file) => `Uploading ${file}`` | An uploading file's progress bar name: (name) => `Uploading ${name}`. |
| `percentLabel` | `(percent: string) => string` | `(percent) => `Uploading ${percent}`` | An uploading chip's line: (percent) => `Uploading ${percent}`. |
| `fileLabel` | `string` | `File` | A chip's kind when neither its name nor its type says it. |
| `addedLabel` | `(names: string[]) => string` | `(files) => `${files.join(", ")} added.`` | Said when files are added: (names) => `${names.join(", ")} added.` |
| `removedLabel` | `(name: string) => string` | `(file) => `${file} removed.`` | Said when a file is removed: (name) => `${name} removed.` |
| `uploadingLabel` | `string` | `Wait for the files to finish uploading.` | Said when Enter is pressed while files still upload. |
| `formatCount` | `(used: number, max: number) => string` | `defaultCount` | The count near the limit, for other languages. |
| `formatRemaining` | `(left: number) => string` | `defaultRemaining` | What screen readers hear near the limit. |

## Shapes its props take

### PromptBoxAttachment

| Prop | Type | Default | What it does |
| --- | --- | --- | --- |
| `id` (required) | `string` |  |  |
| `name` (required) | `string` |  |  |
| `size` | `number` |  | Bytes. |
| `type` | `string` |  | The file's MIME type ("application/pdf", "image/png"), as `File.type` gives it. |
| `kind` | `string` |  | What kind of file it is, when the name's extension does not say it ("Spreadsheet"). |
| `preview` | `string` |  | An image's address (an object URL while it uploads, the stored file's after): shown as the chip's thumbnail. |
| `status` | `"done" \| "error" \| "uploading"` |  | "uploading" shows its progress, "error" its message; default "done". |
| `progress` | `number` |  | 0–100 while uploading. |
| `error` | `string` |  | What went wrong and what to do ("Too large to send. |
| `href` | `string` |  | Where the file opens (in a sent message): the chip becomes a link. |

## Rules it keeps

- `a11y.accessible-name`
- `a11y.keyboard`
- `composition.button-labels`

## Examples

Every example on the page, as one file:

```tsx
import { useEffect, useState } from "react";
import { Globe } from "lucide-react";
import { PromptBox, Toggle } from "turtlekit";
import type { PromptBoxAttachment } from "turtlekit";

/**
 * A prompt with two files: one attached, one still uploading (Send waits for it). Attach picks more; pasting a
 * screenshot or dropping a file on the box adds it too. A tool toggle sits in the lower row.
 */
export function AttachedFiles() {
  const [files, setFiles] = useState<PromptBoxAttachment[]>([
    { id: "contract", name: "brightwater-contract-2026.pdf", size: 412_000, status: "done" },
    { id: "photo", name: "site-visit.jpg", size: 2_300_000, status: "uploading", progress: 64 },
  ]);
  return (
    <PromptBox
      label="Your message"
      placeholder="Ask about these files"
      defaultValue="Does the contract cover the work in the photo?"
      attachments={files}
      accept="image/*,application/pdf"
      maxSize={20_000_000}
      onAttach={(added) =>
        setFiles((list) => [
          ...list,
          ...added.map((file) => ({
            id: `${file.name}-${file.lastModified}`,
            name: file.name,
            size: file.size,
            status: "done" as const,
          })),
        ])
      }
      onRemoveAttachment={(id) => setFiles((list) => list.filter((file) => file.id !== id))}
      actions={<Toggle label="Search the web" icon={<Globe />} />}
      onSubmit={() => setFiles([])}
    />
  );
}

/** Send, then Stop while the reply arrives: the same button, in the same place. The draft field stays open. */
export function SendAndStop() {
  const [replying, setReplying] = useState(false);
  useEffect(() => {
    if (!replying) return;
    // A reply that takes four seconds, unless it is stopped.
    const timer = window.setTimeout(() => setReplying(false), 4000);
    return () => window.clearTimeout(timer);
  }, [replying]);
  return (
    <PromptBox
      label="Your message"
      placeholder="Ask Acme anything"
      maxLength={2000}
      streaming={replying}
      onSubmit={() => setReplying(true)}
      onStop={() => setReplying(false)}
    />
  );
}

/** Offline: why nothing can be sent, under the box. People can still write; Send waits. */
export function WhenOffline() {
  return (
    <PromptBox
      label="Your message"
      placeholder="Ask Acme anything"
      defaultValue="Draft a reminder for INV-0048"
      unavailable="You're offline. You can send once you're back online."
      onSubmit={() => {}}
    />
  );
}
```
