Attachment Tray
A message attachment area — images in a grid with a built-in viewer, files as chips, with optional upload progress and removal.
Attachment Tray
Basic Usage
Attachment Tray
Loading demo...
Interaction Contract
- Attachments are split by
kind:imagegoes to the grid,fileto the chips. Pass both in the sameattachmentsarray. removableis the switch between the two modes: true shows remove and cancel-upload affordances (composer), false makes the whole area read-only (message).- The three events differ in shape.
removeandcancelcarry anid;openis emitted by file chips only, carries the whole attachment, and what "open" means is the consumer's call. - Images have no
openevent — clicking one opens the built-in viewer (built onTxModal), with nothing for the host to wire up. - The viewer pages between images only, and the index is clamped to the valid range. Files take no part in it.
- The viewer title prefers the image's
nameand falls back topreviewTitle. - A thumbnail that fails to load is recorded by
idand replaced with a placeholder, rather than showing the browser's broken-image glyph or retrying. - Upload progress is driven by
uploadingandprogress(0–1) on the attachment, drawn as a ring. - File sizes default to B / KB / MB with one decimal;
sizeFormatterreplaces that entirely.
API
Props
| Name | Type | Default | Description |
|---|---|---|---|
attachments | AiAttachment[] | — | Images and files in one list. Required. |
removable | boolean | false | Whether to show remove and cancel-upload. True in a composer, false on a message. |
previewTitle | string | 'Preview' | Viewer title when the image has no name. |
previousLabel | string | 'Previous image' | Accessible name for the previous button. |
nextLabel | string | 'Next image' | Accessible name for the next button. |
previousText | string | 'Prev' | Visible text on the previous button. |
nextText | string | 'Next' | Visible text on the next button. |
removeLabel | string | 'Remove attachment' | Accessible name for remove buttons. |
cancelLabel | string | 'Cancel upload' | Accessible name for cancel-upload buttons. |
sizeFormatter | (bytes: number) => string | — | Replaces the file size text. Falls back to B/KB/MB. |
Events
| Name | Payload | Description |
|---|---|---|
remove | (id: string) | Emitted when remove is clicked. |
cancel | (id: string) | Emitted when cancel-upload is clicked. |
open | (attachment: AiAttachmentFile) | Emitted by file chips only; images use the built-in viewer. |
Slots
TxAttachmentTray exposes no slots. The image grid and file chip layouts are fixed.
Best Practices
- Pass
removablein a composer and omit it on a message — it is the only signal separating "still editable" from "already sent". removeandcancelgive you anidonly; drop the item from your own list. The component never mutatesattachments.- Set
uploading: trueandprogresstogether on an in-flight attachment; one without the other leaves the ring at zero. - Implement
openfor files, or clicking a file chip does nothing at all. - Override the six label props plus
sizeFormatteron non-English surfaces.previousTextandnextTextare visible text, so missing them is the most obvious.