Skip to content

Commit ddb45db

Browse files
committed
fix(Lightbox): a single photo's caption shows as a gallery's
A single photo laid out its caption on its own: under the photo, centred with it, on a plate as wide as its text. Its caption now shows as a gallery page's does. The photo is the one page of the viewer's track, and its caption sits in the band at the bottom of the viewer, on the same backing, two lines tall with "more" for a longer one. A photo with no caption has no band. Only paging stays a gallery's: a single photo shows no Previous, Next or counter and has no pager, and a drag past a zoomed photo's edge springs back. A zoomable photo's box now takes the stage's cursor, not the reset's button cursor, so a gallery shows the zoom-in cursor over its fitted photo too. The zoom core's fit callback, which only the single photo's caption used, goes.
1 parent 3ed2e7d commit ddb45db

11 files changed

Lines changed: 609 additions & 437 deletions

‎.changeset/lightbox-single-caption-backing.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
'@astryxdesign/core': patch
33
---
44

5-
[fix] A single photo's caption in `Lightbox` now sits on the same backing as a gallery's caption band, so it keeps 4.5:1 contrast over any page behind the viewer.
5+
[fix] A single photo's caption in a `Lightbox` now shows as a gallery's does. It sits in the band at the bottom of the viewer, on the caption's backing, which keeps 4.5:1 over any page behind it. The photo centres above it. A caption longer than two lines ends in "more", which opens it in full over the photo. A single photo with no caption shows no band.
66

77
@vjeux

‎apps/storybook/stories/Lightbox.stories.tsx‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const WithZoom: Story = {
104104
},
105105
};
106106

107-
/** Zoom on a photo with a caption, which sits under the fitted photo. */
107+
/** Zoom on a photo with a caption, in the caption band a gallery's pages use. */
108108
export const ZoomWithCaption: Story = {
109109
render: () => {
110110
const [isOpen, setIsOpen] = useState(false);
@@ -214,6 +214,33 @@ export const GalleryKeepsIndex: Story = {
214214
},
215215
};
216216

217+
/**
218+
* A single photo whose caption runs long. As on a gallery's page, two lines
219+
* cut it short and "more" shows it all.
220+
*/
221+
export const SingleWithLongCaption: Story = {
222+
render: () => {
223+
const [isOpen, setIsOpen] = useState(false);
224+
return (
225+
<>
226+
<button onClick={() => setIsOpen(true)}>
227+
Open single photo with a long caption
228+
</button>
229+
<Lightbox
230+
isOpen={isOpen}
231+
onOpenChange={setIsOpen}
232+
media={{
233+
...GALLERY_MEDIA[0],
234+
caption:
235+
'A winding path through the forest, past the old mill and down to the river, where the trail turns back toward the village. In autumn the beeches along it turn copper, and on a clear morning you can see the church spire from the bridge before the path climbs the last hill home.',
236+
}}
237+
hasZoom
238+
/>
239+
</>
240+
);
241+
},
242+
};
243+
217244
export const WithCaption: Story = {
218245
render: () => {
219246
const [isOpen, setIsOpen] = useState(false);

‎docs/specs/components/Lightbox/Lightbox.spec.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ FR21). Consumer props and usage remain documented in `Lightbox.doc.mjs`.
140140
| ID | Candidate invariant | Basis | Draft review state |
141141
| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | --------------------------- |
142142
| FR1 | The viewer contains one active Media item and a Close button; galleries additionally contain Previous and Next buttons plus a Counter, and Caption renders only when supplied. In a gallery with any caption, every page keeps a band two caption lines tall under its Media, with the caption's backing only where the page has a caption. A longer caption's second line ends in a "more" button that opens it in full over the bottom of the Media, on a scrim. The full caption is always the viewer's accessible description. The caption band uses Astryx parts: the caption text is `Text` with the body type, and "more"/"less" is a ghost `Button`, not hand-styled elements. | Current source, docs, and tests | settled |
143+
| FR1b | A single photo and a set of photos present the caption the same way: the same plate, width, text treatment, inline "more", spacing and photo position, and no plate when there is no caption. (Owner direction, Nov 6 2026 (Cindy): "the behavior for single photo is different than multiple for the caption and they really should be consistent".) Exceptions: a single photo has no Previous or Next button, no Counter and no paging, since there is no other item; and a drag past a zoomed single photo's edge rubber-bands and returns (FR6), where a gallery's pager takes it (FR7). | Owner direction, Nov 6 2026 | settled |
143144
| FR2 | Viewer overlay carries the current `lightbox` target. Media, Caption, and Counter carry no Lightbox public target. | Current source and public docs | settled |
144145
| FR3 | Close, Previous, and Next button surfaces use Button's `button` target through IconButton rather than Lightbox-owned button targets. | Current source and target docs | settled |
145146
| FR4 | The open viewer is a focus region through Core's shared focus-region module (`component:Dialog/DEC-2`): Tab from its last control moves focus to its first and Shift+Tab from its first moves focus to its last, so focus never leaves the viewer for the browser's own interface. | `component:Dialog/DEC-2` | settled; implementation gap |
@@ -332,6 +333,7 @@ a decision that they must remain unthemeable.
332333
| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
333334
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
334335
| FR1 | `Lightbox.test.tsx` render, gallery, caption, media, and zoom suites; the `LightboxViewport` caption band cases | Single image, gallery edges, caption, video | Removing a documented part fails existing role, content, media, or navigation assertions. | `audit:Lightbox/anatomy` |
336+
| FR1b | `Lightbox.test.tsx` single photo cases; `LightboxSingleCaption` interaction specs, Chromium and WebKit, on a phone and a desktop | A single photo with a caption, with zoom, with a long caption and with none, against a gallery page | A single photo whose band, caption text or photo box differs from a gallery page's, a long single caption without "more", a band without a caption, or a Previous, Next or Counter on a single photo fails. | `audit:Lightbox/anatomy` |
335337
| FR2 | Source inspection and `themingTargets.test.ts` | Viewer overlay, Media, Caption, and Counter | Removing the root target or documenting an unshipped child target fails evidence or inventory. | `audit:Lightbox/theming` |
336338
| FR3 | Source inspection plus Button and IconButton public composition | Close and gallery navigation controls | Re-owning a control surface requires the delegated owner and this map to change. | `audit:Lightbox/theming` |
337339
| FR4, AR3 | Browser keyboard test: Tab and Shift+Tab at both ends, Escape, arrows in LTR and RTL, `+`, `-`, `0`, close focus | Single image, gallery, zoomed image, removed opener | Focus leaving the viewer, a key without its action, or focus not returning to a connected opener fails. | `audit:Lightbox/accessibility` |
@@ -340,7 +342,7 @@ a decision that they must remain unthemeable.
340342
| FR11 | Fine-pointer browser tests | Double-click, click on the photo, drag, ctrl-wheel, trackpad scroll, mouse wheel notch | A double-click that does not zoom 2× about the point, a click that hides the controls, a fine-pointer close that animates, or a mouse wheel's notch that pans a zoomed photo fails. | `audit:Lightbox/touch` |
341343
| FR6, AR1 | Touch test double-tapping a photo shaped like the screen and a landscape photo | 9:16 photo on a phone viewport, 3:2 photo | A double tap that zooms less than 2×, or not about the tapped point, fails. | `audit:Lightbox/touch` |
342344
| FR16 | Touch tests closing by Close, Escape, platform close, and a tap beside the photo with the controls shown; Reduce Motion | With and without `experimental`; controls shown and hidden | A touch close without the exit, a literal timing, input reaching the viewer during the exit, or a tap beside the photo that closes while the controls are hidden fails. | `audit:Lightbox/touch` |
343-
| FR17 | Unit: `Lightbox.test.tsx` media surface cases; browser: `LightboxPaging` and `LightboxZoom` interaction specs, Chromium and WebKit | Gallery with captions, with and without zoom; a single photo's caption; over a white, a mid-grey and a black photo (body 14.7:1 over white) | A viewer outside `MediaTheme`, a Lightbox-set text color, a caption or counter that is not `Text`, a toggle that is not a ghost `Button`, two start edges, or a caption under 4.5:1 fails. | `audit:Lightbox/theming` |
345+
| FR17 | Unit: `Lightbox.test.tsx` media surface cases; browser: `LightboxPaging` and `LightboxZoom` interaction specs, Chromium and WebKit | Gallery with captions, with and without zoom; a single photo's caption; over a white and a mid-grey photo (body 14.7:1 over white) | A viewer outside `MediaTheme`, a Lightbox-set text color, a caption or counter that is not `Text`, a toggle that is not a ghost `Button`, two start edges, or a caption under 4.5:1 fails. | `audit:Lightbox/theming` |
344346
| FR12 | Opener and `sourceFor` tests, with and without `experimental` | Image opener, text-button opener, mid-entrance close | Any change to opening or closing without `experimental` fails. | `audit:Lightbox/touch` |
345347
| FR13 | `hasZoom={false}` tests under a coarse pointer | Gallery, single image | A zoom, a pinch close, or a tap that hides the controls with `hasZoom={false}` fails. | `audit:Lightbox/touch` |
346348
| FR14 | Source boundary check and bundle analysis | A page with Lightbox and another touch component | A second copy of a touch module or a Lightbox-owned gesture listener fails. | `audit:Lightbox/touch` |

‎packages/core/src/Lightbox/Lightbox.doc.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const anatomy = [
3232
name: 'Caption',
3333
required: false,
3434
description:
35-
'Caller-provided caption displayed below the active media. In a gallery it shows at most two lines; a longer caption adds a "more" button that opens it in full over the photo.',
35+
'Caller-provided caption displayed below the active media, in a band at the bottom of the viewer. It shows at most two lines, for a single photo as for a gallery; a longer caption adds a "more" button that opens it in full over the photo.',
3636
},
3737
{
3838
name: 'Counter',

0 commit comments

Comments
 (0)