Skip to content

Commit 702b595

Browse files
committed
fix(Lightbox): a single photo's caption sits on the caption's backing
A single photo's caption had no backing, so its white text over the backdrop measured 4.00:1 over a white page, under FR17's 4.5:1. It now sits on the backing that a gallery's caption band uses, reaching below its last line as far as above its first: 17.22:1 over a white page. The record drops the gap.
1 parent c83f03d commit 702b595

4 files changed

Lines changed: 81 additions & 4 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
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.
6+
7+
@vjeux

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ the requirement it misses and the person it affects.
8888
browser that places controls elsewhere pages from them.
8989
- **Tab containment (FR4).** Tab from the viewer's last control can move focus
9090
to the browser's own interface.
91-
- **Single photo's caption contrast (FR17).** A single photo's caption has no
92-
backing. Its white text over the backdrop measures 4.00:1 over a white
93-
page, under FR17's 4.5:1, so a low-vision reader can lose it there.
9491
- **Zoom reset key (AR3).** `0` does not return a zoomed photo to its fitted
9592
size.
9693
- **Zoom announcement (AR4).** A zoom change announces "zoomed in" or "zoomed

‎packages/core/src/Lightbox/Lightbox.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,13 @@ const styles = stylex.create({
494494
maxWidth: '600px',
495495
flexShrink: 0,
496496
},
497+
// A single photo's caption sits on the caption's backing too, so it keeps
498+
// 4.5:1 over any page behind the viewer. The backing reaches below its
499+
// last line as far as above its first.
500+
captionSingle: {
501+
paddingBlockEnd: spacingVars['--spacing-2'],
502+
backgroundColor: CAPTION_BACKING,
503+
},
497504
closeButton: {
498505
position: 'absolute',
499506
top: spacingVars['--spacing-3'],
@@ -1744,7 +1751,7 @@ export function Lightbox({
17441751
id={captionId}
17451752
as="div"
17461753
type="body"
1747-
xstyle={styles.caption}>
1754+
xstyle={[styles.caption, styles.captionSingle]}>
17481755
{currentItem.caption}
17491756
</Text>
17501757
)}

‎packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,72 @@ for (const [photo, fill] of [
550550
});
551551
}
552552

553+
for (const [story, trigger] of [
554+
['core-lightbox--with-caption', 'Open with caption'],
555+
['core-lightbox--zoom-with-caption', 'Open zoom with caption'],
556+
] as const) {
557+
test(`a single photo's caption keeps 4.5:1 on its backing over a white page and photo (${story})`, async ({
558+
page,
559+
}) => {
560+
await page.route('https://picsum.photos/**', async route =>
561+
route.fulfill({
562+
contentType: 'image/svg+xml',
563+
body: '<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800"><rect width="1200" height="800" fill="#ffffff"/></svg>',
564+
}),
565+
);
566+
await page.goto(`${storybook()}/iframe.html?id=${story}&viewMode=story`);
567+
await page.locator('#storybook-root > *').first().waitFor();
568+
// The page behind the viewer is white, the lightest it can be.
569+
await page.addStyleTag({
570+
content:
571+
'html, body, #storybook-root { background: #ffffff !important; }',
572+
});
573+
await frames(page, 2);
574+
const driver = await touchDriver(page);
575+
const opener = await page
576+
.getByRole('button', {name: trigger})
577+
.boundingBox();
578+
if (opener == null) {
579+
throw new Error('no trigger');
580+
}
581+
await driver.tap({
582+
x: opener.x + opener.width / 2,
583+
y: opener.y + opener.height / 2,
584+
});
585+
const dialog = page.getByRole('dialog');
586+
await expect(dialog).toBeVisible();
587+
await expect
588+
.poll(async () =>
589+
dialog
590+
.locator('img')
591+
.first()
592+
.evaluate(img => (img as HTMLImageElement).naturalWidth),
593+
)
594+
.toBe(1200);
595+
// The caption is the viewer's description.
596+
const captionId = await dialog.getAttribute('aria-describedby');
597+
const caption = page.locator(`[id="${captionId}"]`);
598+
await expect(caption).toBeVisible();
599+
await frames(page, 2);
600+
// The caption's colour against the lightest pixel in its top padding,
601+
// above its first line: what the text sits on, with no glyph there.
602+
const {color, points} = await caption.evaluate(element => {
603+
const style = getComputedStyle(element);
604+
const box = element.getBoundingClientRect();
605+
const y = box.top + parseFloat(style.paddingTop) / 2;
606+
return {
607+
color: style.color,
608+
points: [0.25, 0.5, 0.75].map(f => ({x: box.left + box.width * f, y})),
609+
};
610+
});
611+
const shot = PNG.sync.read(await page.screenshot());
612+
const scale = shot.width / (page.viewportSize()?.width ?? shot.width);
613+
expect(
614+
contrast(parseRgb(color), lightestAt(shot, scale, points)),
615+
).toBeGreaterThanOrEqual(4.5);
616+
});
617+
}
618+
553619
test('the stage fills the phone screen and fits the photo', async ({page}) => {
554620
const {state} = await openViewer(page);
555621
const s = await state();

0 commit comments

Comments
 (0)