Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 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
421eec3
test(Lightbox): a click beside the shown photo closes the viewer
vjeux Nov 12, 2026
3616651
fix(Lightbox): a mouse click beside the shown photo closes the viewer
vjeux Nov 12, 2026
b0cc21e
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-click-beside-scaled-photo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[fix] A mouse click on the dark space beside a Lightbox photo now closes the viewer. Before, the viewer stayed open after a click there within the photo's natural width, or within a wider caption's width.

@vjeux
1 change: 0 additions & 1 deletion docs/specs/components/Lightbox/Lightbox.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ the requirement it misses and the person it affects.
close (FR8) are not built for a mouse, a pen or a trackpad: a drag on a
fitted photo does nothing.
On a desktop, a click in the viewer outside the photo and a band holding a caption closes it.
Implementation gap: beside a photo scaled down to fit, a click within the band as wide as the photo's natural width stays open.
With zoom, a double-click on a caption zooms the photo, and a mouse does not select the caption's text, for one photo or a gallery.
- **Double-click listener (FR14).** A mouse's or a pen's double-click reaches
the zoom through the stage's own `dblclick` listener, since only the browser
Expand Down
19 changes: 10 additions & 9 deletions packages/core/src/Lightbox/Lightbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function rectAt(left: number, top: number, width: number, height: number) {
/**
* Lays out a gallery's current page for a mouse's click: its photo's box,
* natural width and caption, and the viewer's width. jsdom lays out nothing.
* The photo's laid-out width is its shown width without zoom.
*/
function layOutPage(
page: Element,
Expand All @@ -164,6 +165,7 @@ function layOutPage(
define(img, {
getBoundingClientRect: () => photo,
offsetHeight: photo.height,
offsetWidth: photo.width,
naturalWidth: natural,
});
// The photo's own box hugs it without zoom.
Expand Down Expand Up @@ -837,7 +839,7 @@ describe('Lightbox', () => {
});
mousePress(box, {x: 300, y: 200});
expect(onOpenChange).not.toHaveBeenCalled();
// Beside the photo, past its natural width, the click is the backdrop's.
// Beside the photo, the click is the backdrop's.
mousePress(box, {x: 20, y: 200});
expect(onOpenChange).toHaveBeenCalledWith(false);
});
Expand Down Expand Up @@ -1070,7 +1072,7 @@ describe('Lightbox', () => {
);
});

it("stays open on a mouse click beside a narrow photo, within its caption's width", () => {
it("closes on a mouse click beside a narrow photo, level with it, within its caption's width", () => {
const onOpenChange = vi.fn();
render(
<Lightbox
Expand All @@ -1088,15 +1090,13 @@ describe('Lightbox', () => {
caption: rectAt(100, 410, 400, 30),
viewer: 1000,
});
// The media is as wide as the caption here, so this point is on it.
// The caption's band sits under the photo. Beside the photo, level
// with it, the click is the backdrop's, even within the caption's width.
mousePress(box, {x: 150, y: 250});
expect(onOpenChange).not.toHaveBeenCalled();
// Past the caption's width, the click is the backdrop's.
mousePress(box, {x: 50, y: 250});
expect(onOpenChange).toHaveBeenCalledWith(false);
});

it('stays open on a mouse click beside a large photo, level with it, since its media spans the viewer', () => {
it('closes on a mouse click beside a large photo shown smaller, level with it', () => {
const onOpenChange = vi.fn();
render(
<Lightbox
Expand All @@ -1107,7 +1107,8 @@ describe('Lightbox', () => {
/>,
);
const current = document.querySelector('[data-current]')!;
// A photo wider than the viewer, shown at 400 px.
// A photo wider than the viewer, shown at 400 px. The media is the
// shown photo, not its natural width.
layOutPage(current, {
photo: rectAt(300, 100, 400, 200),
natural: 3000,
Expand All @@ -1117,7 +1118,7 @@ describe('Lightbox', () => {
x: 990,
y: 200,
});
expect(onOpenChange).not.toHaveBeenCalled();
expect(onOpenChange).toHaveBeenCalledWith(false);
});

it('shows gallery counter', () => {
Expand Down
12 changes: 3 additions & 9 deletions packages/core/src/Lightbox/Lightbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1149,9 +1149,8 @@ export function Lightbox({
);
// Whether a mouse's or a pen's click on the media closes the viewer. It
// does when its press or its release lands outside the current page's
// media. That is the fitted photo's rows, as wide as the photo's natural
// width or the caption, up to the viewer's, and the caption's own box.
// While zoomed, the photo's shown box is media too.
// media. That is the fitted photo's laid-out box, the caption's band and
// the caption's own box. While zoomed, the photo's shown box is media too.
const isClickOutsideMedia = useCallback((e: ReactMouseEvent<HTMLElement>) => {
const viewer = imageWrapperRef.current;
const page = viewer?.querySelector('[data-current]');
Expand All @@ -1177,12 +1176,7 @@ export function Lightbox({
const top = boxRect.top + space;
const bottom = top + media.offsetHeight;
const caption = page.querySelector<HTMLElement>('[data-lightbox-caption]');
const natural =
media instanceof HTMLImageElement ? media.naturalWidth : media.videoWidth;
const width = Math.min(
viewer.clientWidth,
Math.max(natural, caption?.offsetWidth ?? 0),
);
const width = media.offsetWidth;
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
const middle = boxRect.left + box.clientWidth / 2;
const shown = media.getBoundingClientRect();
// The caption band can sit apart from the photo. There the media is the
Expand Down
167 changes: 108 additions & 59 deletions packages/core/src/Lightbox/LightboxFinePointer.a11y.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,61 @@ test('a mouse click above the photo closes the viewer with zoom on, as before',
});
});

test('in a gallery, a mouse click beside a large photo, level with it, leaves the viewer open, as on main', async ({
test('in a gallery, a mouse click beside a large photo shown smaller, level with it, closes the viewer', async ({
page,
}) => {
// A photo wider than the viewer: the media spans the viewer's width, so
// a click beside the photo stays on it, as on main.
// A photo wider than the viewer is shown smaller. The media is the shown
// photo, not its natural width, so a click beside it is the backdrop's.
const {dialog, current} = await openGallery(page);
const shown = await boxOf(current);
expect(shown.x).toBeGreaterThan(40);
const level = shown.y + shown.height * 0.15;
await page.mouse.click(shown.x / 2, level);
await page.waitForTimeout(400);
await expect(dialog).toBeVisible();
await expectBackdropClickCloses(page, dialog, {x: shown.x / 2, y: level});
});

test('at 1280 × 800, a mouse click 4 or 20 px beside a gallery photo scaled down to fit closes the viewer, and one on the photo or its caption band keeps it open', async ({
page,
}) => {
await page.setViewportSize({width: 1280, height: 800});
// The story's own photo size, which the window scales down to fit.
await page.route('https://picsum.photos/**', async route =>
route.fulfill({
contentType: 'image/svg+xml',
body: photoSvg(1200, 800),
}),
);
const open = async () => {
await page.goto(
`${storybook.origin}/iframe.html?id=core-lightbox--gallery-with-zoom&viewMode=story`,
);
await page.getByRole('button', {name: 'Open gallery with zoom'}).click();
const dialog = page.getByRole('dialog');
await expect(dialog).toBeVisible();
const current = dialog.locator('[data-current] img');
await expect
.poll(async () =>
current.evaluate(el => (el as HTMLImageElement).naturalWidth),
)
.toBe(1200);
await settled(page);
return {dialog, shown: await boxOf(current)};
};
let {dialog, shown} = await open();
expect(shown.width).toBeLessThan(1200);
const level = shown.y + shown.height / 2;
for (const gap of [4, 20]) {
await expectBackdropClickCloses(page, dialog, {x: shown.x - gap, y: level});
({dialog, shown} = await open());
}
expect(await staysOpenAfterClick(page, centre(shown))).toBe(true);
const {band, caption} = await captionBoxes(dialog);
expect(band.x).toBeLessThan(caption.x - 12);
expect(
await staysOpenAfterClick(page, {
x: band.x + 12,
y: caption.y + caption.height / 2,
}),
).toBe(true);
});

test('a mouse click on the gallery counter leaves the viewer open, as on main', async ({
Expand All @@ -471,7 +514,7 @@ test('a mouse click on the gallery counter leaves the viewer open, as on main',
await expect(dialog).toBeVisible();
});

test('without zoom, a mouse click at the far edge beside a large gallery photo leaves the viewer open, as on main', async ({
test('without zoom, a mouse click at the far edge beside a large gallery photo closes the viewer', async ({
page,
}) => {
await page.setViewportSize({width: 1280, height: 800});
Expand All @@ -497,9 +540,10 @@ test('without zoom, a mouse click at the far edge beside a large gallery photo l
const shown = await boxOf(current);
// The photo leaves dark area at the window's right edge, level with it.
expect(1280 - (shown.x + shown.width)).toBeGreaterThan(20);
await page.mouse.click(1276, shown.y + shown.height / 2);
await page.waitForTimeout(400);
await expect(dialog).toBeVisible();
await expectBackdropClickCloses(page, dialog, {
x: 1276,
y: shown.y + shown.height / 2,
});
});

test('a mouse double-click zooms 2× about the clicked point, and the next zooms back', async ({
Expand Down Expand Up @@ -736,23 +780,20 @@ async function staysOpenAfterClick(
return page.evaluate(() => document.querySelector('dialog')?.open === true);
}

test('a mouse click beside the fitted photo, level with it, leaves the viewer open, as on main', async ({
test('a mouse click beside the fitted photo, level with it, closes the viewer on either side', async ({
page,
}) => {
const {fitted, stageBox} = await openViewer(page);
// The fitted photo leaves dark stage on both sides. Main's media spans the
// viewer's width there, so a click beside the photo does not close.
const {dialog, fitted, stageBox} = await openViewer(page);
// The fitted photo leaves dark stage on both sides, where a click is the
// backdrop's.
expect(fitted.x - stageBox.x).toBeGreaterThan(40);
const level = fitted.y + fitted.height / 2;
expect(await staysOpenAfterClick(page, {x: stageBox.x + 20, y: level})).toBe(
true,
);
expect(
await staysOpenAfterClick(page, {
x: fitted.x + fitted.width + 20,
y: level,
}),
).toBe(true);
await expectBackdropClickCloses(page, dialog, {x: stageBox.x + 20, y: level});
const again = await openViewer(page);
await expectBackdropClickCloses(page, again.dialog, {
x: again.fitted.x + again.fitted.width + 20,
y: level,
});
});

test('with zoom on, a mouse click on the photo leaves the viewer open and one below it closes, as on main', async ({
Expand Down Expand Up @@ -805,7 +846,7 @@ test('a mouse press on the fitted photo released above it closes the viewer, as
).toBe(false);
});

test('without zoom, a mouse click beside the photo leaves the viewer open and one above it closes, as on main', async ({
test('without zoom, a mouse click beside the photo or above it closes the viewer', async ({
page,
}) => {
await page.route('https://picsum.photos/**', async route =>
Expand Down Expand Up @@ -836,7 +877,7 @@ test('without zoom, a mouse click beside the photo leaves the viewer open and on
x: fitted.x / 2,
y: fitted.y + fitted.height / 2,
}),
).toBe(true);
).toBe(false);
await page.setViewportSize({width: 1280, height: 1100});
const tall = await open();
expect(tall.y).toBeGreaterThan(40);
Expand Down Expand Up @@ -942,46 +983,54 @@ test('with zoom, a mouse double-click on a single photo’s caption zooms the ph
);
});

test('in a gallery with zoom, a mouse click beside a small photo closes past its caption’s width and stays open within it, as on main', async ({
test('in a gallery with zoom, a mouse click beside a narrow photo, level with it, closes the viewer within its caption’s width or past it', async ({
page,
}) => {
// A photo narrower than the viewer: the media is as wide as its caption,
// which is wider than the photo here.
// A photo narrower than its caption. The caption's band sits under the
// photo, so the dark space beside the photo is the backdrop's.
await page.setViewportSize({width: 1280, height: 1100});
await page.route('https://picsum.photos/**', async route =>
route.fulfill({contentType: 'image/svg+xml', body: photoSvg(200, 1200)}),
);
await page.goto(
`${storybook.origin}/iframe.html?id=core-lightbox--gallery-with-zoom&viewMode=story`,
);
await page.getByRole('button', {name: 'Open gallery with zoom'}).click();
const dialog = page.getByRole('dialog');
await expect(dialog).toBeVisible();
const img = dialog.getByRole('img').first();
await expect
.poll(async () => img.evaluate(el => (el as HTMLImageElement).naturalWidth))
.toBe(200);
await settled(page);
const photo = await boxOf(img);
// The current page's own caption.
const caption = await dialog.evaluate(viewer => {
const r = viewer
.querySelector('[data-current] [data-lightbox-caption]')
?.getBoundingClientRect();
return r == null ? null : {x: r.x, width: r.width};
});
if (caption == null) {
throw new Error('no caption');
}
const level = photo.y + photo.height / 2;
const open = async () => {
await page.goto(
`${storybook.origin}/iframe.html?id=core-lightbox--gallery-with-zoom&viewMode=story`,
);
await page.getByRole('button', {name: 'Open gallery with zoom'}).click();
const dialog = page.getByRole('dialog');
await expect(dialog).toBeVisible();
const img = dialog.getByRole('img').first();
await expect
.poll(async () =>
img.evaluate(el => (el as HTMLImageElement).naturalWidth),
)
.toBe(200);
await settled(page);
// The current page's own caption.
const caption = await dialog.evaluate(viewer => {
const r = viewer
.querySelector('[data-current] [data-lightbox-caption]')
?.getBoundingClientRect();
return r == null ? null : {x: r.x, width: r.width};
});
if (caption == null) {
throw new Error('no caption');
}
return {dialog, photo: await boxOf(img), caption};
};
const first = await open();
const level = first.photo.y + first.photo.height / 2;
// Within the caption's width, beside the photo.
expect(caption.x).toBeLessThan(photo.x - 10);
expect(
await staysOpenAfterClick(page, {x: (caption.x + photo.x) / 2, y: level}),
).toBe(true);
expect(first.caption.x).toBeLessThan(first.photo.x - 10);
await expectBackdropClickCloses(page, first.dialog, {
x: (first.caption.x + first.photo.x) / 2,
y: level,
});
// Past the caption's width.
expect(caption.x).toBeGreaterThan(60);
expect(await staysOpenAfterClick(page, {x: caption.x - 30, y: level})).toBe(
false,
);
const second = await open();
expect(second.caption.x).toBeGreaterThan(60);
await expectBackdropClickCloses(page, second.dialog, {
x: second.caption.x - 30,
y: level,
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ test('without zoom, a mouse press beside the photo that is released on it closes
}
});

test('without zoom, a mouse click beside a photo narrower than its caption leaves the gallery open, as on main', async ({
test('without zoom, a mouse click beside a photo narrower than its caption, level with it, closes the gallery', async ({
browser,
}) => {
const context = await browser.newContext({
Expand Down Expand Up @@ -671,9 +671,10 @@ test('without zoom, a mouse click beside a photo narrower than its caption leave
);
}, beside),
).toBe(true);
// The caption's band sits under the photo, so this point is the
// backdrop's.
await page.mouse.click(beside.x, beside.y);
await frames(page, 40);
await expect(dialog).toBeVisible();
await expect(dialog).toBeHidden();
} finally {
await context.close();
}
Expand Down
Loading
Loading