Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
d2e76e4
fix(Lightbox): a single photo's caption sits on the caption's backing
vjeux Nov 8, 2026
d398515
fix(Lightbox): a single photo's caption shows as a gallery's
vjeux Nov 8, 2026
b64c3d4
feat(Lightbox): a gallery's caption sits in a two-line band
vjeux Nov 8, 2026
50875b6
docs(Lightbox): caption notes and records cover a single photo
vjeux Nov 8, 2026
232f499
test(Layer): the one-gutter check lists Lightbox's full-screen viewer
vjeux Nov 8, 2026
b565bdc
docs(Lightbox): FR1b covers a single captioned video too
vjeux Nov 8, 2026
18d4bb5
Merge main into the caption band
vjeux Nov 8, 2026
9a9b0f7
Merge the caption band's main merge
vjeux Nov 8, 2026
801fa11
docs(Lightbox): FR1b quotes only the owner's exact words
vjeux Nov 8, 2026
f2fdc74
Merge main into the caption band
vjeux Nov 8, 2026
785873b
Merge the caption band's second main merge
vjeux Nov 8, 2026
5877a0e
Merge main's drag to close into the caption band
vjeux Nov 8, 2026
cd2e283
fix(Lightbox): a drag to close fades a gallery's caption band
vjeux Nov 8, 2026
5c56c40
feat(Lightbox): a caption's "more" and "less" are an inline link
vjeux Nov 8, 2026
c6efc6e
Merge the caption band's main merge and inline link
vjeux Nov 8, 2026
926524a
fix(Lightbox): the caption's toggle takes its touch target from Core
vjeux Nov 8, 2026
d6950dc
Merge the caption band's touch target fix
vjeux Nov 8, 2026
d038a4b
Merge main's tempo for the drag to close into the caption band
vjeux Nov 8, 2026
2b0b009
Merge the caption band's main merge for the drag to close's tempo
vjeux Nov 8, 2026
29779c1
Merge main's first truncation measurement into the caption band
vjeux Nov 8, 2026
cff0218
Merge the caption band's merge of main's truncation measurement
vjeux Nov 8, 2026
74a1798
Merge main's nearest-item index into the caption band
vjeux Nov 9, 2026
f4874b7
Merge the caption band's merge of main's nearest-item index
vjeux Nov 9, 2026
ef505e3
Merge main's busy proof test fixes into the caption band
vjeux Nov 9, 2026
f782a98
Merge the caption band's merge of main's busy proof test fixes
vjeux Nov 9, 2026
f53cbe5
fix(Lightbox): "more" and "less" take the caption's colour
vjeux Nov 9, 2026
79b5a27
Merge the caption band's toggle colour fix
vjeux Nov 9, 2026
36836d2
Merge main's Lightbox screen reader and zoom reset changes
vjeux Nov 9, 2026
24cb6d1
Merge the caption band's merge of main
vjeux Nov 9, 2026
48232ac
fix(Lightbox): the caption measures through one shared observer path
vjeux Nov 9, 2026
1c6211d
Merge the caption band's shared observer path
vjeux Nov 9, 2026
c450f37
Merge main
vjeux Nov 9, 2026
7de97bf
Merge the caption band's merge of main
vjeux Nov 9, 2026
0412ac8
fix(Lightbox): the caption's toggle sits on a whole line box
vjeux Nov 9, 2026
84aeecf
Merge the caption band's whole line box for the toggle
vjeux Nov 9, 2026
f27d557
fix(Lightbox): the toggle's place is as tall as the caption's lines
vjeux Nov 9, 2026
12f50c4
Merge the caption toggle place made of line boxes
vjeux Nov 9, 2026
558fa34
fix(Lightbox): an open caption's toggle place shrinks when it widens
vjeux Nov 10, 2026
cd23648
Merge the open caption toggle place that shrinks when it widens
vjeux Nov 10, 2026
547f67e
fix(Lightbox): an opened caption counts its lines without the toggle
vjeux Nov 10, 2026
fceae0c
Merge the opened caption that counts its lines without the toggle
vjeux Nov 10, 2026
59a4256
Merge main
vjeux Nov 10, 2026
2d69149
Merge main
vjeux Nov 10, 2026
2a2aa33
fix(Lightbox): keep internal markers off public data attributes
vjeux Nov 10, 2026
e7e9aef
fix(Lightbox): new text in an open caption counts its lines again
vjeux Nov 10, 2026
766883d
docs(Lightbox): name where focus goes after paging from the toggle
vjeux Nov 10, 2026
5eddce8
Merge the caption band's attribute and recount fixes
vjeux Nov 10, 2026
8e8db8e
fix(Lightbox): a click on the caption band leaves the viewer open
vjeux Nov 10, 2026
36ec042
Merge the caption band's click rule
vjeux Nov 10, 2026
5b1475c
docs(Lightbox): a double-click on a caption zooms the photo
vjeux Nov 10, 2026
b482541
docs(Lightbox): state the desktop click rule in the present
vjeux Nov 10, 2026
d12f0d5
test(Lightbox): a gallery's caption keeps 4.5:1 in light mode
vjeux Nov 10, 2026
61845c0
Merge main
vjeux Nov 10, 2026
a1763d2
Merge the caption band's present-tense click rule and main
vjeux Nov 10, 2026
381fc24
docs(Lightbox): state the caption double-click rule in the present
vjeux Nov 10, 2026
4ecd6d4
test(Lightbox): time the tap after a drag to close as a browser does
vjeux Nov 10, 2026
2ab9123
test(Lightbox): a single photo's caption keeps 4.5:1 in every theme
vjeux Nov 10, 2026
f111a96
docs(Lightbox): FR19's verification row names the black photo again
vjeux Nov 10, 2026
23b396f
test(Lightbox): a single captioned video takes a gallery page's band
vjeux Nov 10, 2026
d30de85
Merge main
vjeux Nov 11, 2026
1e1a1ea
Merge the caption band's merge of main
vjeux Nov 11, 2026
520db91
Merge main
vjeux Nov 11, 2026
34f0792
Merge the caption band's merge of main
vjeux Nov 11, 2026
e0b9691
Merge main
vjeux Nov 11, 2026
5058dc3
Merge the caption band's merge of main
vjeux Nov 11, 2026
230cff7
Merge main
vjeux Nov 11, 2026
07d4ce9
Merge the caption band's merge of main
vjeux Nov 11, 2026
591999d
fix(Lightbox): a new caption is measured as it renders
vjeux Nov 11, 2026
a9c43b7
test(Text): useTruncation keeps its answer while text is expanded
vjeux Nov 11, 2026
d99c0ce
feat(Text): useTruncation takes isExpanded, and Lightbox uses it
vjeux Nov 11, 2026
edea6cf
Merge main
vjeux Nov 11, 2026
5e008ff
Merge main
vjeux Nov 11, 2026
1990c0c
docs(architecture): name observeResizeAfterLayout under INV18
vjeux Nov 11, 2026
b7d1fd4
Merge the caption band's merge of main
vjeux Nov 11, 2026
cdb270a
Merge main
vjeux Nov 11, 2026
c987368
Merge the caption band's merge of main
vjeux Nov 11, 2026
0d55126
Merge main
vjeux Nov 11, 2026
648c343
Merge the caption band's merge of main
vjeux Nov 11, 2026
7480d1d
fix(Lightbox): a gallery's photo box keeps the stage's cursor
vjeux Nov 12, 2026
84d4ec2
Merge the caption band's photo cursor fix
vjeux Nov 12, 2026
e4b4eaf
docs(Lightbox): name the natural-width click gap in the record
vjeux Nov 12, 2026
7282678
Merge the caption band's record of the click gap
vjeux Nov 12, 2026
439bd0c
Merge main
vjeux Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/lightbox-single-caption-backing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[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.

@vjeux
29 changes: 28 additions & 1 deletion apps/storybook/stories/Lightbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const WithZoom: Story = {
},
};

/** Zoom on a photo with a caption, which sits under the fitted photo. */
/** Zoom on a photo with a caption, in the caption band a gallery's pages use. */
export const ZoomWithCaption: Story = {
render: () => {
const [isOpen, setIsOpen] = useState(false);
Expand Down Expand Up @@ -241,6 +241,33 @@ export const GalleryKeepsIndex: Story = {
},
};

/**
* A single photo whose caption runs long. As on a gallery's page, two lines
* cut it short and "more" shows it all.
*/
export const SingleWithLongCaption: Story = {
render: () => {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<button onClick={() => setIsOpen(true)}>
Open single photo with a long caption
</button>
<Lightbox
isOpen={isOpen}
onOpenChange={setIsOpen}
media={{
...GALLERY_MEDIA[0],
caption:
'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.',
}}
hasZoom
/>
</>
);
},
};

export const WithCaption: Story = {
render: () => {
const [isOpen, setIsOpen] = useState(false);
Expand Down
10 changes: 5 additions & 5 deletions docs/specs/components/Lightbox/Lightbox.spec.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/core/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1697,11 +1697,11 @@
},
"@astryx.lightbox.captionMore": {
"defaultMessage": "more",
"description": "Visible label of the button after a gallery caption that two lines cut short in a Lightbox. It opens the full caption over the photo. Pairs with `lightbox.captionLess`."
"description": "Visible label of the button after a Lightbox caption that two lines cut short, for a single photo or a gallery. It opens the full caption over the photo. Pairs with `lightbox.captionLess`."
},
"@astryx.lightbox.captionLess": {
"defaultMessage": "less",
"description": "Visible label of the same button while a Lightbox gallery's full caption is open over the photo. It closes the full caption. Pairs with `lightbox.captionMore`."
"description": "Visible label of the same button while a Lightbox caption is open in full over the photo. It closes the full caption. Pairs with `lightbox.captionMore`."
},
"@astryx.metadataList.showMore": {
"defaultMessage": "Show more",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Lightbox/Lightbox.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const anatomy = [
name: 'Caption',
required: false,
description:
'Caller-provided caption displayed below the active media. In a gallery it shows at most two lines; a longer caption ends in an inline "more" link that opens it in full over the photo.',
'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 ends in an inline "more" link that opens it in full over the photo.',
},
{
name: 'Counter',
Expand Down
191 changes: 127 additions & 64 deletions packages/core/src/Lightbox/Lightbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,73 @@ describe('Lightbox', () => {
});
});

describe('a single photo', () => {
it("renders as a gallery's page: its photo's box, then its caption in the band below", () => {
render(
<Lightbox
isOpen={true}
onOpenChange={() => {}}
media={{src: '/photo.jpg', alt: 'Photo', caption: 'A caption'}}
/>,
);
const pages = document.querySelectorAll('[data-lightbox-page]');
expect(pages).toHaveLength(1);
const page = pages[0];
expect(page).toHaveAttribute('data-current');
const media = page.querySelector('[data-lightbox-page-media]')!;
expect(media).toContainElement(screen.getByAltText('Photo'));
const caption = page.querySelector<HTMLElement>(
'[data-lightbox-caption]',
)!;
expect(caption).toHaveTextContent('A caption');
expect(media.nextElementSibling).toContainElement(caption);
// Nothing to page to: no Previous, Next or counter.
expect(screen.queryByRole('button', {name: 'Previous'})).toBeNull();
expect(screen.queryByRole('button', {name: 'Next'})).toBeNull();
expect(screen.queryByText('1 / 1')).toBeNull();
});

it("gives a single captioned video a gallery page's box and band, and its caption describes the viewer", () => {
render(
<Lightbox
isOpen={true}
onOpenChange={() => {}}
media={{
src: '/clip.mp4',
alt: 'A clip',
type: 'video',
caption: 'A caption',
}}
/>,
);
const page = document.querySelector('[data-lightbox-page]')!;
expect(page).toHaveAttribute('data-current');
const media = page.querySelector('[data-lightbox-page-media]')!;
expect(media.querySelector('video')).toHaveAttribute('src', '/clip.mp4');
const caption = page.querySelector<HTMLElement>(
'[data-lightbox-caption]',
)!;
expect(caption).toHaveTextContent('A caption');
expect(media.nextElementSibling).toContainElement(caption);
expect(screen.getByRole('dialog')).toHaveAccessibleDescription(
'A caption',
);
});

it('with no caption has no band, as a gallery with none', () => {
render(
<Lightbox
isOpen={true}
onOpenChange={() => {}}
media={{src: '/photo.jpg', alt: 'Photo'}}
/>,
);
const page = document.querySelector('[data-lightbox-page]')!;
expect(page.children).toHaveLength(1);
expect(page.querySelector('[data-lightbox-caption]')).toBeNull();
});
});

it('does not crash with an empty media array', () => {
const {container} = render(
<Lightbox isOpen={true} onOpenChange={() => {}} media={[]} />,
Expand All @@ -1765,7 +1832,7 @@ describe('Lightbox', () => {
});

describe('backdrop dismiss', () => {
it('closes on a click on the strip a raised caption leaves below the stage', () => {
it("closes on a mouse click above a single photo, as on a gallery's page", () => {
const onOpenChange = vi.fn();
render(
<Lightbox
Expand All @@ -1775,14 +1842,16 @@ describe('Lightbox', () => {
hasZoom
/>,
);
// The media group: the stage, then the caption's place below it. A
// mouse's click there is below the raised caption.
const group = screen.getByText('A caption').parentElement!;
fireEvent.click(group, {detail: 1, clientY: 590});
// The stage centres the 200 px photo in its 600 px box.
const current = document.querySelector('[data-current]')!;
mousePress(current.querySelector('[data-lightbox-page-media]')!, {
x: 200,
y: 20,
});
expect(onOpenChange).toHaveBeenCalledWith(false);
});

it('without zoom, leaves a click beside a narrower caption alone', () => {
it("without zoom, leaves a mouse click on a single photo's caption alone", () => {
const onOpenChange = vi.fn();
render(
<Lightbox
Expand All @@ -1791,8 +1860,17 @@ describe('Lightbox', () => {
media={{src: '/photo.jpg', alt: 'Photo', caption: 'A caption'}}
/>,
);
// The media group hugs its media and caption, as before.
fireEvent.click(screen.getByText('A caption').parentElement!);
const current = document.querySelector('[data-current]')!;
layOutPage(current, {
photo: rectAt(100, 200, 200, 200),
natural: 200,
caption: rectAt(50, 560, 300, 40),
viewer: 400,
});
mousePress(current.querySelector('[data-lightbox-caption]')!, {
x: 200,
y: 580,
});
expect(onOpenChange).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -2048,9 +2126,12 @@ describe('Lightbox gestures for a mouse and a pen (spec:AST-094 FR43)', () => {
await act(async () => {
await new Promise(resolve => setTimeout(resolve, 400));
});
// Each caption click reads its own press, not the drag's.
// Each caption click reads its own press, not the drag's. The caption
// sits in its band, on the stage's surface, so its presses are timed as a
// browser times them: now.
const caption = screen.getByText('A caption');
for (const at of [t0 + 1000, t0 + 2000]) {
for (let i = 0; i < 2; i++) {
const at = performance.now();
pointer('pointerdown', caption, 'mouse', 200, 300, at);
pointer('pointerup', caption, 'mouse', 200, 300, at + 40);
fireEvent.click(caption, {clientX: 200, clientY: 300, detail: 1});
Expand Down Expand Up @@ -2138,12 +2219,12 @@ describe('Lightbox gestures for a mouse and a pen (spec:AST-094 FR43)', () => {
pointer('pointerup', stage, 'mouse', 180, 300, t0 + 32);
fireEvent.click(stage, {clientX: 180, clientY: 300, detail: 1});
expect(onOpenChange).not.toHaveBeenCalled();
// A new press on the dark area above starts a new click, which closes.
const container =
screen.getByText('A caption').parentElement!.parentElement!;
pointer('pointerdown', container, 'mouse', 200, 10, t0 + 1000);
pointer('pointerup', container, 'mouse', 200, 10, t0 + 1040);
fireEvent.click(container, {clientX: 200, clientY: 10, detail: 1});
// A new press on the dark area above, on the stage, starts a new click,
// which closes. It is timed as a browser times it: now.
const later = performance.now();
pointer('pointerdown', stage, 'mouse', 200, 10, later);
pointer('pointerup', stage, 'mouse', 200, 10, later + 40);
fireEvent.click(stage, {clientX: 200, clientY: 10, detail: 1});
expect(onOpenChange).toHaveBeenCalledWith(false);
});
});
Expand Down Expand Up @@ -2207,6 +2288,7 @@ describe('Lightbox recognizers attach for every pointer (spec:AST-094 FR43)', ()
}

it('attaches no drag to dismiss where the primary pointer is fine', () => {
// Only the backdrop's tap beside the photo, as on a gallery's page.
expect(
lightboxRecognizersAttached(() => {
render(
Expand All @@ -2217,7 +2299,7 @@ describe('Lightbox recognizers attach for every pointer (spec:AST-094 FR43)', ()
/>,
);
}),
).toEqual([]);
).toEqual(['lightbox-backdrop-tap']);
});

it('attaches the drag to dismiss under the touch layer', () => {
Expand Down Expand Up @@ -2301,24 +2383,6 @@ describe('Lightbox touch zoom (synthetic touches)', () => {
});
}

/** A finger's pointerdown, which a browser sends before its touchstart. */
function fingerDown(target: Element, x: number, y: number): void {
const event = new Event('pointerdown', {bubbles: true, cancelable: true});
const fields = {pointerType: 'touch', pointerId: 2, isPrimary: true};
for (const [key, value] of Object.entries({
...fields,
button: 0,
buttons: 1,
clientX: x,
clientY: y,
})) {
Object.defineProperty(event, key, {value});
}
act(() => {
target.dispatchEvent(event);
});
}

it('reports a tap beside the photo to the newest onOpenChange', async () => {
// The stage's gestures read the props of the latest render, so a parent's
// new callback is the one a tap beside the photo reaches.
Expand Down Expand Up @@ -2346,7 +2410,7 @@ describe('Lightbox touch zoom (synthetic touches)', () => {
['a fitted photo', false],
['a zoomed photo', true],
])(
'closes on a finger’s tap on the strip after a finger drag on %s, once the drag’s flag is clear',
'closes on a finger’s tap beside the photo after a finger drag on %s',
async (_, isZoomedFirst) => {
const onOpenChange = vi.fn();
render(
Expand All @@ -2372,17 +2436,13 @@ describe('Lightbox touch zoom (synthetic touches)', () => {
touch('touchmove', stage, [finger], [finger], 1000 + i * 16);
}
touch('touchend', stage, [], [finger], 1000 + 7 * 16);
const group = screen.getByText('A caption').parentElement!;
const tapStrip = () => {
fingerDown(group, 200, 590);
fireEvent.click(group, {clientX: 200, clientY: 590, detail: 1});
};
// A zoomed drag's flag takes the first tap. A fitted photo's drag starts
// no zoom pan, since paging owns it, so it leaves no flag.
tapStrip();
expect(onOpenChange).toHaveBeenCalledTimes(isZoomedFirst ? 0 : 1);
tapStrip();
expect(onOpenChange).toHaveBeenCalledWith(false);
// Above the photo, on the stage: its own tap closes the viewer, as on a
// gallery's page. The drag leaves nothing in its way.
const tap: Contact = {id: 7, x: 200, y: 50};
touch('touchstart', stage, [tap], [tap], 2000);
touch('touchend', stage, [], [tap], 2040);
// A single tap waits out a double tap's interval.
await waitFor(() => expect(onOpenChange).toHaveBeenCalledWith(false));
},
);

Expand Down Expand Up @@ -2425,7 +2485,7 @@ describe('Lightbox touch zoom (synthetic touches)', () => {
touch('touchend', stage, [], [a], 20 * 16);
});

it("takes a caption off the photo from a pinch's first move", () => {
it('keeps a single photo’s caption in its band, outside the photo’s box, through a pinch', () => {
render(
<Lightbox
isOpen={true}
Expand All @@ -2435,10 +2495,12 @@ describe('Lightbox touch zoom (synthetic touches)', () => {
/>,
);
const stage = screen.getByRole('button', {name: 'Zoom'});
const caption = screen.getByText('A caption');
// Fitted, the caption is raised by the stage's free space below the
// photo: (600 - 200) / 2.
expect(caption.style.translate).toBe('0 -200px');
const caption = stage.parentElement!.querySelector<HTMLElement>(
'[data-lightbox-caption]',
)!;
// The band is the page's row below the photo's box, as on a gallery's.
expect(stage).not.toContainElement(caption);
expect(caption.style.translate).toBe('');
let a: Contact = {id: 1, x: 150, y: 300};
let b: Contact = {id: 2, x: 250, y: 300};
touch('touchstart', stage, [a], [a], 0);
Expand All @@ -2448,10 +2510,12 @@ describe('Lightbox touch zoom (synthetic touches)', () => {
b = {...b, x: 250 + 6 * i};
touch('touchmove', stage, [a, b], [a, b], i * 16);
}
// Both fingers are still down, and the photo spreads over the stage.
// Both fingers are still down, and the photo spreads over the stage. The
// caption stays in its band, unmoved.
expect(
parseFloat(photoTransform(screen.getByAltText('Photo')).scale),
).toBeGreaterThan(1);
expect(stage).not.toContainElement(caption);
expect(caption.style.translate).toBe('');
touch('touchend', stage, [a], [b], 5 * 16);
touch('touchend', stage, [], [a], 6 * 16);
Expand Down Expand Up @@ -2573,7 +2637,7 @@ describe('Lightbox touch zoom (synthetic touches)', () => {
expect(onOpenChange).not.toHaveBeenCalled();
});

it('ignores the first tap on the strip after a drag to close springs back, as before', async () => {
it('closes on a finger’s tap beside the photo after a drag to close springs back', async () => {
const onOpenChange = vi.fn();
render(
<Lightbox
Expand All @@ -2593,16 +2657,15 @@ describe('Lightbox touch zoom (synthetic touches)', () => {
touch('touchend', stage, [], [finger], clock + 7 * 16);
await new Promise(resolve => setTimeout(resolve, 50));
expect(onOpenChange).not.toHaveBeenCalled();
const group = screen.getByText('A caption').parentElement!;
const tapStrip = () => {
fingerDown(group, 200, 590);
fireEvent.click(group, {clientX: 200, clientY: 590, detail: 1});
};
// The first tap on the strip below the stage only clears the drag's flag.
tapStrip();
expect(onOpenChange).not.toHaveBeenCalled();
tapStrip();
expect(onOpenChange).toHaveBeenCalledWith(false);
// Above the photo, on the stage: its own tap closes the viewer, as on a
// gallery's page. The drag leaves nothing in its way. The tap is timed as
// a browser times it: now.
const tap: Contact = {id: 7, x: 200, y: 50};
const now = performance.now();
touch('touchstart', stage, [tap], [tap], now);
touch('touchend', stage, [], [tap], now + 40);
// A single tap waits out a double tap's interval.
await waitFor(() => expect(onOpenChange).toHaveBeenCalledWith(false));
});
});

Expand Down
Loading
Loading