Media viewer
ProA full-screen viewer for a set of photos: swipe between them, zoom, and read each caption and position. Not an M3 component (@windmorph/react-pro).
import { MediaViewer } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Keyboard
| Key | Action | Where |
|---|---|---|
| Tab or Shift + Tab | Move between the controls: Close, Zoom out, Zoom in, your actions, Previous and Next, and an expandable caption. Focus stays in the viewer. | |
| Arrow Left or Arrow Right | Show the previous or next photo. While zoomed, they pan the photo instead. | |
| Arrow Up or Arrow Down | Pan the photo while zoomed. Unzoomed, they do nothing. | |
| Home or End | Show the first or last photo. | |
| Arrow Up or Arrow Down or Page Up or Page Down | Scroll an expanded caption that is longer than its space.On the caption | On the caption |
| + or - | Zoom in or out (= and _ work too). | |
| 0 | Resets the zoom. | |
| Escape | Closes the viewer. | |
| Enter or Space | Press the focused control, or expand and collapse a cut caption. |
- In right-to-left layouts Arrow Left and Arrow Right swap, so Arrow Left shows the next photo.
- Hold Shift while panning to move four times as far (48px a press, 192px with Shift).
- The viewer's keys are ignored when Alt, Ctrl or ⌘ is held, and inside text fields or content portalled from
actions, such as an open menu.
Screen reader
- Role
- A modal
dialog: the core's full-screenDialog. - Accessible name
- Its required
aria-labeloraria-labelledby("Photos from Alex's post"). - States announced
- A cut caption is a
buttonwitharia-expanded. Zoom buttons are disabled when they can go no further.
- The position ("Photo 2 of 7",
labels.position) is a polite live region, read when the photo changes. A single photo has no position. - The current photo is read by its
alt. The preloaded photos on each side are hidden from assistive tech (aria-hidden,inert). - With no caption, the alt text is also shown as the caption, hidden from screen readers (
aria-hidden) since the photo is already named by it; if it's cut, its expand button is named bylabels.description. - Every control's name is also its tooltip, the core icon button's own, so it isn't read twice.
- A photo that can't be loaded shows
labels.errorin its place. - The page behind is hidden from assistive tech while the viewer is open.
Focus
- When it opens, focus moves to its first control (Close), as in any core dialog, and Tab and Shift + Tab stay inside it until it closes. When it closes, focus returns to the element that had it, usually the thumbnail that opened it.
- Previous and Next disappear at the first and last photo. Pressing one to get there moves focus to the other; otherwise focus falls back to the viewer, so the keys keep working.
- When the focused zoom button becomes disabled, focus moves to the other zoom button after a press, or to the viewer after a key.
- Every control shows M3's focus indicator on keyboard focus.
Touch target
- Close, the zoom buttons and icon buttons in
actionsare small icon buttons (40px) with an invisible 48 × 48px touch target, kept at density 0 whatever the theme density. Previous and Next are 56px tonal icon buttons. - Previous and Next show on every window size, so moving between photos never needs a swipe (WCAG 2.5.7).
- On touch a swipe down closes the viewer, which the Close button also does. A double-tap or double-click, a pinch, or Ctrl or ⌘ with the wheel zooms, as the zoom buttons and keys do.
Motion
- It opens and closes with the core full-screen dialog's motion: it slides up and fades in, or, given an
origin, grows out of that thumbnail and shrinks back into it (the M3 container transform). Under reduced motion it only fades. - Photos slide to the next one and zoom eases into place; under reduced motion both snap. While a finger or pointer is down they follow it without easing.
What you need to do
- Name the viewer with
aria-labeloraria-labelledby, and give every photo analtthat says what it shows. - Pass
labelsfrom your translations: every word it shows or announces comes from there, including the position. - Give every control in
actionsa name; an icon button needs anaria-label. - Open it from a real control, such as a
MediaGridtile, so focus has somewhere to return to. - Name the expand button of an alt-text caption with
labels.descriptionin your language.