Lightbox
Photos one at a time over the page, in the modal layer. ds::lightbox is the
dialog; x-ds-lightbox="name" marks its openers; dsLightbox fills it.
Anatomy
┌───────────────────────────────────────────────┐ .dark, fixed, z-50
│ 3 / 12 [⊕] [↗] [✕] │ ← counter (aria-hidden), zoom, original, close
│ │
│ [‹] ┌───────────────┐ [›] │ ← stage: placeholder, image, loader, error
│ │ photo │ │
│ └───────────────┘ │
│ Caption text │
│ [▫][▫][■][▫][▫][▫][▫][▫] │ ← strip: role=toolbar, one Tab stop
└───────────────────────────────────────────────┘
| Part | Token | Why |
|---|---|---|
| Layer | dark class on the layer | Photos are seen on near-black in either theme; every token below takes its dark value with nothing written twice. |
| Ground | surface-sunken, opaque, on the panel itself | Near-black over a light page and a dark one alike; the panel being its own ground, its text is measured against it. |
| Controls | size-10, rounded-full, hover:bg-fg/10, disabled:opacity-30; Previous and Next on fg/10 | Round targets on a dark ground; Previous at the first photo is disabled, not hidden, so the layout never shifts. |
| Image | max-h-full max-w-full, m-auto; dialog-enter duration and easing | The slide between photos is the image's own transition on translate and opacity, motion-safe. |
| Placeholder | the thumbnail, blur-xl, opacity-60 while loading | The photo's shape and colours at once. |
| Thumb | size-12, opacity-60; current opacity-100 + ring-2 ring-fg | The current one by ring and brightness, not colour alone. |
The layer
The modal recipe (Support\Modal::recipe()): x-effect focus (focus into the
panel, the stack, the scroll lock, focus back to _returnFocusTo), the Tab
trap, Escape when topmost, and covered for a layer over it. The panel is
role=dialog, aria-modal, tabindex=-1, focused on open so the arrows work.
Openers
x-ds-lightbox is a directive (an enhancement, no Behaviour::data): its
expression is a literal name. A plain click (primary button, no modifier)
finds [data-ds-lightbox="name"]; if there is one, the click is prevented and
the lightbox opens at that opener, else the link is followed. The photos are
every [x-ds-lightbox] of that name in document order, read at each open,
hidden ones included. Per opener: data-ds-lightbox-src or href;
-srcset; -alt or the inner img's alt; the inner img's currentSrc as the
thumbnail; -caption.
States
data-ds-state on the panel: loading (after 100 ms without the decoded
photo, or at once when there is no photo yet or after an error), ready,
error (the message and Try again). data-ds-zoomed and data-ds-still
(no transition, during a drag) on the stage.
Moving
Left / Right in the reading direction, Home / End, the buttons, the strip
(roving, shared/roving.js), a swipe (shared/drag.js, slop 8 px, axis
decided at the start; past a quarter of the stage or flung, it moves). A swipe
down closes when dismissible. Each move updates the dialog's name ("Photo
n of m: alt") and says it in a polite status region; opening does not, as the
dialog's name is read on focus. The neighbours are preloaded.
Zoom
Between 1 (fit) and the photo's full size, at least 2×. Click (mouse) or
double tap (300 ms) on the photo, a pinch (shared/pan-zoom.js, shared with
avatar-upload), + = / - _, or the Zoom button (aria-pressed). When
zoomed a drag pans and the arrows pan (40 px, 120 with Shift); the
translation is clamped so an edge never comes inside the stage. A move resets
it.
Focus back
Each photo shown, if its opener is visible, becomes _returnFocusTo, so
closing lands on the tile of the photo last looked at; a hidden one (past a
grid's max) leaves it on the last visible one.
Accessibility
- Role and name:
role=dialog,aria-modal, named "Photo n of m: alt" fromlabel. The image has its alt; the placeholder and counter are hidden. - Keyboard:
| Key | Does |
|---|---|
| Left / Right | Previous / next (reversed in RTL); pans when zoomed |
| Up / Down | Pan when zoomed |
| Home / End | First / last |
+ = / - _ | Zoom to full / to fit |
| Escape | Close |
| Tab | Round the controls and the strip (one stop), held in the dialog |
- Focus: into the panel on open; back to the opener (above) on close.
- Motion: the slide and the fade are
motion-safe; under reduced motion the photo is replaced in place.
Do not
- Close on any click on the stage. A click ending a pan, or on the image, must not close: only a press on the stage itself or the placeholder.
- Read the photos once at init. A host adds openers later (a Livewire page, infinite scroll); they are read at each open.
- Make the swipe the only way. Every gesture has a key and a button.
From the package repo: edit this page on GitHub.