ImageViewer
One image full screen to look at closely, with pinch, wheel and double-tap zoom, panning, and Escape or a swipe down to close.
Stability: experimental
Props
| Prop | Type | Default | Means |
|---|---|---|---|
src | string | The image address; shown at once when an Image already decoded it. | |
alt | string | What the image shows: the dialog's name and its caption. | |
open | boolean | bindable(false) | Whether the viewer is showing. Bind it with bind:open={name}; closing sets it to false. |
States
| State | Looks like |
|---|---|
open | The canvas colour over the whole screen, fading in over 160 ms (none with reduced motion), the caption and a close button at the top. |
zoomed | The image from 1x to 4x around the fingers or pointer; dragging pans it, never showing a gap at an edge. |
swiping | Not zoomed, the image follows a drag down; let go past 96 points to close, or it springs back. |
Accessibility
| role | dialog named by alt; aria-modal while open |
| name | The alt prop. |
| focus | Opening moves focus to the close button; Tab and Shift+Tab stay inside; closing returns focus to where it was, such as the Image that opened it. It is a dialog on the shared overlay layer (decision 0034), which also makes the page behind it inert and still; written inside another overlay, such as a Dialog, it closes with that overlay (its open becomes false) and focus goes back to where it was before the Dialog opened. |
| keyboard | Escape closes. Enter or Space on the close button closes. |
| notes | Zoom comes from <image zoomable> (decision 0039); the zoom level is in data-zoom on the image. |
Theme tokens
color.canvas color.ink color.raised color.muted space.3 space.4 space.6 radius.full text.label text.caption
Example
<ImageViewer src="/photos/city.svg" alt="A city at dusk" bind:open={viewing} />