← All proposals

Composer

A labelled textarea with a toolbar inside the same bordered box:

Net-new componentOpen in Storybook

proposals/Composer/Composer.mdx50 lines · View on GitHub
import { Canvas, Controls, Meta, Title } from '@storybook/addon-docs/blocks';

import * as ComposerStories from './Composer.stories';

<Meta of={ComposerStories} name='Usage' />

<Title />

## Purpose

A labelled textarea with a toolbar inside the same bordered box. It has a configurable footer utility section for buttons. Used for AI Chat interfaces.

## Usage

Use it to compose a prompt on chat and agent screens.

- There are four slots. `aboveField` sits on the top edge outside the border, `fieldHeader` sits inside the border above the text (for attachments), and the toolbar is `actionsStart` and `actionsEnd`. The screen decides what goes in them; the usual set is `IconButton`s, a bare `Select` for the model and a primary `IconButton` for Send.
- Keep the label and the helper message, as on every PDS input. The label is required and read by screen readers, but hidden on screen by default (the placeholder says what the field is for); set `showLabel` to show it.
- The field can be resized by dragging the bottom corner.
- Pass `onFilesDrop` to let people drag files onto the field. The field shows a dashed border (and the optional `dropLabel`, which is also read to screen readers) while a file is over it, and hands the dropped files to the handler. Dragged text still drops into the textarea. Try it on the sample below: drag a file onto the field. The screen decides what to do with the files. Drop is off while the field is `disabled`.
- `variant='compact'` is a single-line bar with the controls on the same row; it is not resizable.
- Enter and Shift+Enter are not handled here; the screen decides what sends.
- For plain multi-line text with no toolbar, use `Textarea`. Composer leaves out `Textarea`'s required marker, label tooltip, character counter, read-only state, `inputWidth` and validation states; use `Textarea` if you need them.
- `variant='compact'` is a variant, not a boolean, because it changes the DOM order (the controls sit in the same row as the text).

## Accessibility

- The `label` is a real `<label>` tied to the textarea. It is hidden on screen by default and still read by screen readers; the `message` is linked with `aria-describedby`.
- The textarea is native, so typing and keyboard behavior are the browser's. Enter and Shift+Enter are not handled here.
- The focus ring shows on the whole field whenever the textarea or a toolbar control has focus. Toolbar controls keep their own focus styles and keyboard behavior.
- In `compact` the DOM order is start controls, text, end controls, the same as the visual order, so Tab follows what you see.
- File drop is a pointer shortcut. While files are dragged over the field, a visually hidden status region (`role='status'`, polite) reads `dropLabel`, and the visible overlay is hidden from assistive technology. Always give keyboard users another way to add files (for example the add menu).
- When the field sits in a Chat Panel that also has a `dropLabel`, both announce their label while files are over the field. Use the same wording or leave one out.
- If attachments fail, write one `role='alert'` helper message in `message` (shown in the With Attachment Errors story).
- Not checked: the a11y panel has not been run for light or dark.

## Implementation

See the table below for the available props. The other stories show every variant and state.

- `isResizable` — Can the user resize the field by dragging its corner?
- `rows` — Number of visible text rows above the toolbar.
- `size` — Field size. Sets the padding.
- `textareaProps` — Additional props for the `<textarea>` element.

<hr />

<Canvas of={ComposerStories.Slots} />
<Controls of={ComposerStories.Default} />