Talisman LogoTalisman Logo Design System
Browse documentation
Components

Image viewer

Turns an inline image into a full-viewport viewer with zoom, pan, rotation and optional annotations.

Stableimport { ImageViewer } from "@repo/ui/image-viewer";Source
Comprovante de pagamento

Select the image to open the viewer. Use the toolbar to zoom and rotate, drag to move, and press Escape to close.

When to use

  • To let the user inspect a scanned document, a receipt or a photo that is too small to read inline.
  • To show evidence with an annotation, such as a highlighted amount, on top of the image.
  • Wherever a preview of an attachment appears in a card, a table row or a task.

When not to use

  • PDF files. Use the PDF viewer, which has pages, search and text selection.
  • Spreadsheets and CSV files. Use the Tabular viewer.
  • Decorative images or logos. Use a plain img.
  • A gallery with next and previous. The viewer shows one image; build the list around it.

Anatomy

The component is a wrapper. You pass the inline preview as children, and the viewer takes over when the user selects it.

Part Role
children The inline preview. A transparent button covers it and opens the viewer.
Dialog Full-viewport modal with a solid background, named by alt and described by labels.instructions.
Toolbar Zoom out, zoom level, zoom in, fit, rotate left and rotate right. Shown once the image loads.
Close button Top right corner, labelled with labels.close.
overlay Optional annotations, drawn above the image and rotating with it.

Examples

Annotation over the image

overlay is positioned in the image’s own coordinates, so use percentages for top, left, width and height. It is not interactive. The same shape appears in the viewer after the user opens it.

Comprovante de pagamento

Inside a card

Keep other controls outside the preview slot, and put the caption next to it.

Comprovante de pagamento

Enviado pelo cliente em 14/03/2025

Content

  • alt names the document: “Comprovante de pagamento do processo 0001234-56.2024.8.26.0100”. It becomes the dialog title.
  • labels.open is an action: “Ampliar imagem”.
  • labels.instructions explains the interaction for screen reader users: “Use os botões para ampliar, reduzir e girar. Arraste para mover. Pressione Escape para fechar.”
  • Every key in labels is required. Pass them from the app translations.

Accessibility

  • Built on Radix Dialog: focus moves into the viewer on open, stays inside it, and returns to the trigger when it closes with Escape or the close button.
  • The dialog is named by alt and described by labels.instructions, both visually hidden.
  • The trigger is a native button with aria-label={labels.open} that covers the preview, with a visible focus outline.
  • The image area is a labelled region that takes focus once the image loads. With it focused: + and - zoom, 0 fits, and the arrow keys pan. Zoom runs from 100% to 800%.
  • Zoom and rotate also have buttons with tooltips and accessible names.
  • Toolbar buttons are 44px, above the touch target minimum. Zoom out and zoom in are disabled at the limits.
  • Loading and error messages use role="status". After an error the Retry button reloads the image.
  • Annotations in overlay are hidden from assistive technology (aria-hidden). Do not use them as the only place for important information.

Code

import { ImageViewer } from "@repo/ui/image-viewer";

<ImageViewer
  alt="Comprovante de pagamento"
  labels={labels}
  src={attachment.url}
>
  <img alt="Comprovante de pagamento" src={attachment.thumbnailUrl} />
</ImageViewer>;

In apps/app, wrap it once so every call passes translated labels, as ImageZoom does.

Props

ImageViewer
PropTypeDefaultDescription
altstring—Names the image and the dialog. Describe the document, not the action
childrenReactNode—Inline preview shown on the page. Keep interactive controls out of it
classNamestring—Extra classes for the wrapper around the preview
labelsImageViewerLabels—Every visible and accessible string, translated by the app. All keys are required
onOpenChange(open: boolean) => void—Called when the viewer opens or closes
openboolean—Controlled open state
overlayReactNode—Non-interactive annotations positioned in percentages of the image
srcstring—URL of the image shown in the viewer
ImageViewerLabels (all required)
PropTypeDefaultDescription
openstring—Label of the button over the preview.
closestring—Label of the close button.
zoomInstring—Label of the zoom in button.
zoomOutstring—Label of the zoom out button.
fitstring—Label of the fit to viewport button.
rotateLeftstring—Label of the rotate counterclockwise button.
rotateRightstring—Label of the rotate clockwise button.
loadingstring—Message while the image loads.
errorstring—Message when the image fails to load.
retrystring—Label of the retry button.
instructionsstring—Hidden description of the dialog for assistive technology.

The zoom range, the geometry that fits the image in the viewport and the zoom steps live in image-viewer-zoom.ts, image-viewer-geometry.ts and image-viewer-canvas.tsx. They are internal and are documented here only.

Known issues

Issue Effect
The trigger button covers the whole preview (absolute inset-0) and takes its only name from labels.open. Screen reader users hear “Ampliar imagem” but not which image. Put the document name in labels.open.
ImageViewerCanvas is keyed by src, and the viewer has no previous or next control. Reviewing several attachments means closing and reopening the viewer; zoom and rotation reset on each.
The keyboard shortcuts (+, -, 0, arrows) work only while the image region itself has focus, not the toolbar buttons. They are not announced anywhere except in the text you pass as labels.instructions.
Edit this page on GitHub