The files on a sent message
One picture keeps its own shape. Anything else becomes a grid of square tiles on the sender’s side, above the text. Past four files the grid folds the rest behind a count and opens in place. Pressing a file opens it in the viewer.
In a message
Pass the group to a chat message and it sits outside the bubble, above the text. Pictures and files share one grid.
A single picture
One picture is not squared off. A wide screenshot stays wide, and a tall receipt is capped in height so it cannot take over the thread.
More than four
The last cell stands for the files behind it. Press it and the grid expands where it is, with a button underneath to fold it again.
Files that have gone
A file that has expired stays on the message as a record of what was sent. It opens nothing.
Props
Read from the same JSDoc that ships in the package's types. A required prop is marked with an asterisk.
| Prop | Type | Default | Description |
|---|---|---|---|
items* | AttachmentItem[] | The files on the message, in order. | |
align | "start" | "end" | 'start' | Which edge the layout hugs: `end` for the sender's own turns. |
max | number | 4 | Most cells shown before the rest collapse. Over the limit, the last
cell becomes a "+N" button standing for the hidden files. |
open | boolean | Whether the overflow is expanded, for controlled use. Pair with `onOpenChange`. | |
defaultOpen | boolean | false | Whether the overflow starts expanded, for uncontrolled use. |
onOpenChange | ((open: boolean) => void) | Fires when the overflow expands or collapses. | |
viewer | boolean | true | Open a pressed file in the built-in AttachmentViewer, which steps
through the rest of the group. Turn it off to handle presses yourself
through `onItemClick`. |
onItemClick | ((item: AttachmentItem) => void) | Fires when a file is pressed, whether or not the viewer opens. | |
renderPreview | ((item: AttachmentItem) => ReactNode) | Passed to the viewer: draws a file it cannot, such as the pages of a PDF. | |
onDownload | ((item: AttachmentItem) => void) | Passed to the viewer: fires when Download is pressed, and renders the buttons. | |
onRetry | ((item: AttachmentItem) => void) | Passed to the viewer: fires when "Try again" is pressed on a file that failed to load. | |
size | "default" | "compact" | 'default' | Tile size, passed to every tile. |
label | string | 'Attachments' | Accessible label for the list. |
showMoreLabel | ((hidden: number) => string) | (hidden) => `Show ${hidden} more` | Builds the accessible label of the "+N" button from the hidden count. |
showLessLabel | string | 'Show fewer' | Text of the collapse button under an expanded group. |
attachmentTileLabels | Pick<AttachmentTileProps, "uploadingLabel" | "errorLabel" | "unavailableLabel" | "progressLabel"> | The status lines and progress name every tile writes, merged over the tile's English defaults ("Uploading…", "Upload failed", "Unavailable"). | |
attachmentViewerLabels | Pick<AttachmentViewerProps, "closeLabel" | "downloadLabel" | "previousLabel" | "nextLabel" | "retryLabel" | "noPreviewLabel" | "failedLabel" | "failedDescription" | "formatPosition"> | The words the built-in viewer writes, merged over its English defaults: its buttons ("Download", "Close", "Previous file", "Next file", "Try again"), its fallback headlines and the position text ("2 of 5"). | |
locale | string | The BCP 47 locale file sizes are written in, such as `de-DE` (`1,5 MB`). Defaults to the nearest LocaleProvider's, else `en-US`. | |
className | string | '' | Additional CSS classes |
Tested keys
An automated test presses every row below, in a left-to-right and a right-to-left layout.
The control that shows the rest of the files follows the WAI-ARIA disclosure pattern.
| Key | What it does |
|---|---|
Enter | Opens what it controls, and closes it when it is open. |
Space | Does the same as Enter. |
// From the npm package
import { AttachmentGroup } from 'rift-ds/components/AttachmentGroup/AttachmentGroup';
// Or as source you own, via the shadcn CLI
npx shadcn@latest add https://rift-ds.com/r/attachment-group.json14.4 kB gzipped, with everything it imports. Peer dependencies are not counted.
For agents: the props, their allowed values and defaults, and the tested keys, as markdown or as a JSON schema.
