Open a file without leaving the conversation
A dialog on a wide screen and a full-screen sheet on a narrow one. The header names the file, its size and its place in the set. The viewer shows pictures itself, and a PDF or a text file in place when it carries its own address. The host can draw anything else. When there is nothing to show, it says so plainly.
Pictures
Several pictures share one viewer. The footer steps through them, the arrow keys do the same, and the header says where you are.
Documents in place
A PDF or a text file with a fileUrl opens in place, in the browser’s own viewer, under the viewer’s header. Where a browser will not embed it, the viewer says so and offers the download.
Drawn by the host
The viewer carries no document renderer of its own. Pass a function and the host draws what the viewer cannot, such as a document’s pages as pictures, or a spreadsheet.
Nothing to show
A format with no preview says so beside its mark, name and size, and offers the download.
A file that would not load
When a file fails or its link has expired, the viewer explains and offers another try.
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 |
|---|---|---|---|
open* | boolean | Whether the viewer is open. | |
onOpenChange* | (open: boolean) => void | Fires when the viewer asks to close: the close button, Escape, or the backdrop. | |
items* | AttachmentItem[] | The files the viewer steps through, in order. | |
activeId | string | Id of the file on show, for controlled use. Pair with `onActiveChange`. | |
defaultActiveId | string | Id of the file shown first, for uncontrolled use. Defaults to the first item. | |
onActiveChange | ((id: string) => void) | Fires with the id of the file stepped to. | |
renderPreview | ((item: AttachmentItem) => ReactNode) | Draws a file the viewer cannot: the pages of a PDF, a media player, a
rendered spreadsheet. Return nothing to fall back to the built-in view. | |
onDownload | ((item: AttachmentItem) => void) | Fires with the file on show when Download is pressed. Its presence renders the buttons. | |
onRetry | ((item: AttachmentItem) => void) | Fires with a file that failed to load when "Try again" is pressed. Its presence renders the button. | |
dismissible | boolean | true | Whether Escape, the backdrop and the close button dismiss the viewer. |
downloadLabel | string | 'Download' | Text of the Download buttons. |
closeLabel | string | 'Close' | Accessible label for the close button. |
previousLabel | string | 'Previous file' | Accessible label for the previous-file button. |
nextLabel | string | 'Next file' | Accessible label for the next-file button. |
retryLabel | string | 'Try again' | Text of the retry button. |
noPreviewLabel | string | 'No preview for this file type' | Headline when a file has nothing the viewer can draw. |
failedLabel | string | 'Couldn’t load this file' | Headline when a file failed to load or is no longer available. |
failedDescription | string | 'The link may have expired.' | Sentence under `failedLabel`, when the file carries no error message of its own. |
formatPosition | ((position: number, total: number) => string) | (position, total) => `${position} of ${total}` | Builds the position text, e.g. "2 of 5", from a one-based index and the total. |
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 — applied to the portal container, not the panel. |
Tested keys
An automated test presses every row below, in a left-to-right and a right-to-left layout.
Attachment viewer follows the WAI-ARIA dialog pattern.
| Key | What it does |
|---|---|
On open | Opening moves focus inside. |
Tab | Moves to the next control inside, and from the last back to the first. Focus never reaches the page behind. |
ShiftTab | Moves to the previous control inside, and from the first to the last. |
Escape | Closes it and returns focus to what opened it. |
// From the npm package
import { AttachmentViewer } from 'rift-ds/components/AttachmentViewer/AttachmentViewer';
// Or as source you own, via the shadcn CLI
npx shadcn@latest add https://rift-ds.com/r/attachment-viewer.json11.5 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.