Prompt box
PromptBox
Where a person writes to an AI agent: a growing field, Send that turns to Stop, and attached files.
When to use it: At the foot of a chat or an assistant panel. Enter sends; Shift+Enter starts a new line.
Example
Guidelines
- Give every button, link and icon button a name, every image alt text (alt="" for decoration), and every SVG aria-hidden or role="img" with a name.
a11y.accessible-name - Reach a custom control (role="button", "tab", "checkbox" and the like) with Tab and work it with Enter and Space, or use the native element or the kit component.
a11y.keyboard - Label buttons with a verb and an object ("Save settings", "Delete 3 projects").
composition.button-labels
Add it to your project
It’s included in turtlekit.css and the turtlekit package: install it.
Your AI will also copy only this component, and what it needs, into your project. That comes with Turtlekit Pro, opening soon. Hear when it opens.
In detail
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.
Styles: css/prompt-box.css, css/field.css, css/button.css, css/feedback.css.
How it’s built
The engineering patterns inside PromptBox, each explained in Turtlekit Editorial.
Controlled and uncontrolled components
The draft is value with onValueChange, or kept inside from defaultValue, through useControllableState.
Lifting state up
The app owns the attachments and their upload state, and the reply's streaming; the box reports files added and removed, sends and stops, and renders what it is given.
Deriving state
Whether it can send, the count near the limit and the waiting for uploads are derived from the draft, the attachments and the props during render.
Effect separation
Moving focus to the field when a reply ends under a focused Stop, and measuring the field where the browser cannot size it to its content, live in effects.