Attachment Tray
A tray that displays a message's image and file attachments.
Usage
Basic
Loading demo...
Best Practices
- Set
removablein a composer; leave it off on sent messages so they stay read-only. - Handle
removeandcancelby dropping thatidfrom your list; the component never mutatesattachments. - Give an in-flight attachment both
uploading: trueandprogress(0–1); withoutprogress, no progress shows. - Handle
open; otherwise clicking a file chip does nothing. - On non-English surfaces, override every text prop and
sizeFormatter;previousTextandnextTextare visible text.
API Reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
attachments | AiAttachment[] | — | Images and files in one list. Required. |
removable | boolean | false | Shows remove buttons; cancel-upload buttons don't depend on it. |
previewTitle | string | 'Preview' | Viewer title when the image has no name. |
previousLabel | string | 'Previous image' | Accessible name of the previous button. |
nextLabel | string | 'Next image' | Accessible name of the next button. |
previousText | string | 'Prev' | Visible text of the previous button. |
nextText | string | 'Next' | Visible text of the next button. |
removeLabel | string | 'Remove attachment' | Accessible name of remove buttons. |
cancelLabel | string | 'Cancel upload' | Accessible name of cancel-upload buttons. |
sizeFormatter | (bytes: number) => string | — | Formats file sizes; defaults to B/KB/MB with one decimal. |
Events
| Name | Payload | Description |
|---|---|---|
remove | (id: string) | Fires when remove is clicked. |
cancel | (id: string) | Fires when cancel-upload is clicked. |
open | (attachment: AiAttachmentFile) | Fires when a file chip is clicked; images open the built-in viewer. |
Overview
kind: 'image'items go to the image grid andkind: 'file'items to file chips; pass both in oneattachmentsarray.- Clicking an image opens the built-in viewer (on
TxModal), which pages through images only and emits nothing. - An
uploadingattachment always shows a cancel button: images draw a progress ring, file chips show a percentage. - A thumbnail that fails to load becomes a placeholder and is not retried.