Skip to content

fix(Lightbox): the caption's text keeps 4.5:1 on the counter's backing - #10826

Closed
cixzhang wants to merge 5 commits into
mainfrom
fix/lightbox-caption-contrast
Closed

cixzhang wants to merge 5 commits into
mainfrom
fix/lightbox-caption-contrast

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

User impact

In light mode, a Lightbox caption's white text sat on the light translucent backdrop, so people with low vision could struggle to read it: as low as 2.6:1 against the 4.5:1 that WCAG 1.4.3 requires for 17px text. The caption now sits on the counter's dark translucent backing, line by line, and every shipped theme measures 6.8:1 or better, light and dark. Contrast is proven for the shipped themes and Core's default tokens.

What changes

  • Lightbox.tsx: the caption's content is wrapped in an inline backing span with the counter's existing backing (--color-on-light at 75%, a full radius, --spacing-2 inline padding), cloned per line with box-decoration-break. Each line gains the backing's 8px inline padding on each side, so a caption grows 16px wider, or wraps one line sooner when it's near the width limit (see the phone case below). The span composes the counter's backing style, so the backing lives in one place. The viewer backdrop is unchanged.
  • Lightbox.spec.md AR9: the caption's text keeps 4.5:1 over the backdrop in every shipped theme, light and dark. The verification row names the new browser test.
  • LightboxZoom.interaction.browser.spec.ts: a browser test per theme (all shipped themes plus Core's default tokens) and mode measures the caption's text against the backdrop beside its first line, and fails under 4.5:1. It fails on main in light mode.
  • Lightbox.test.tsx: the unit tests find the caption by its box, since the text now sits in the backing span.

Evidence: real Chrome 157, same measurement as the new test

The caption's text colour against the lightest backdrop pixel just beside its first line, on Storybook's Lightbox / With Caption, before (main) and after (this branch):

Theme Light, before Light, after Dark, before Dark, after
Core default tokens 2.64 14.80 18.87 20.50
Neutral 4.00 13.77 20.62 19.44
Butter 3.33 11.75 17.44 17.21
Chocolate 2.70 7.65 18.73 13.27
Gothic 8.83 14.61 16.41 16.41
Matcha 2.60 6.79 11.45 10.22
Stone 3.11 10.17 16.04 15.46
Y2K 3.12 10.29 19.09 16.42

Desktop (1280×800) and mobile (390×844) give the same ratios.

Neutral, light

Before After
Desktop desktop before light desktop after light
Mobile mobile before light mobile after light

Neutral, dark

Before After
Desktop desktop before dark desktop after dark
Mobile mobile before dark mobile after dark

Core default tokens, light (the lowest before)

Before After
Desktop core desktop before core desktop after
Mobile core mobile before core mobile after

Blank backdrop and zoomed photo, two themes (desktop)

Blank backdrop: the caption under a fitted photo. Zoomed photo: a double click zooms the photo, which fills the stage above the caption.

Blank backdrop, Neutral

Before After
Light blank neutral light before blank neutral light after
Dark blank neutral dark before blank neutral dark after

Blank backdrop, Butter

Before After
Light blank butter light before blank butter light after
Dark blank butter dark before blank butter dark after

Zoomed photo, Neutral

Before After
Light photo neutral light before photo neutral light after
Dark photo neutral dark before photo neutral dark after

Zoomed photo, Butter

Before After
Light photo butter light before photo butter light after
Dark photo butter dark before photo butter dark after

Layout change on a phone: a caption can wrap one line sooner

On a 402px-wide phone in light mode, the With Caption story's caption goes from 2 lines to 3 in Matcha and Y2K: the caption grows 28px (68 to 96px) and the photo, centred with it, moves up 14px. In Neutral it stays at 2 lines at 402px. At 390px it's Neutral's caption that goes from 2 lines to 3, while Matcha and Y2K already wrap to 3 lines before the change. So the extra line depends on the theme's font and the screen width.

Theme Before After
Matcha matcha phone before matcha phone after
Y2K y2k phone before y2k phone after

Checks

  • Lightbox unit tests pass (4 files, 154 tests). Lint, Prettier, check:changesets and check:knowledge pass.
  • The new browser test runs in CI's interaction leg.
  • A design owner accepts the look (DEC-14).

Writing rubric results

  • Present tense, describes the system: yes (AR9's added sentence and its verification row).
  • No history, pull requests or research in the record: yes.
  • Owner routing: the caption's contrast stays in component:Lightbox AR9, beside the controls' contrast it shares a backing with.
  • One topic per sentence: yes.

…very shipped theme

A browser test opens a captioned Lightbox in each shipped theme and Core's
default tokens, light and dark, and measures the caption's text against the
backdrop beside its first line. Lightbox AR9 names the check. It fails on
main: in light mode the light caption text sits on the light backdrop.
The caption's light text sat on a light theme's translucent backdrop, as
low as 2.6:1. It now sits on the counter's dark translucent backing, an
inline span cloned per line, so the caption box keeps its size and place.
The unit tests find the caption by its box.
@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 10, 2026 12:14am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 9, 2026
@astracat-bot

astracat-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟡 Reviewed (for maintainers only) Nov 11, 2026, 1:28 AM UTC

@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 9, 2026
@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 7ba2553

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 33484d6

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Lightbox · Storybook 122.7 kB (+39 B) · 10.6 kB CSS (+31 B) 3,430 (+18) ✓ · ✓ · ✓
lab/Comments 351.5 kB (+30 B) · 2.5 kB CSS (0) — — · — · —
lab/CommentThread 344.5 kB (+24 B) · 2.4 kB CSS (0) — — · — · —

Package size: @astryxdesign/core 7.22 MB packed (+248 B); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 29 rows, core 36 rows, theme-butter 1 row, theme-y2k 1 row; run pnpm api:report.

Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 19d939e

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes. The caption backing fixes light-mode contrast: the new browser test passes in every shipped theme and Core's default tokens, light and dark, and fails on main in seven light cases. One wording fix remains.

  • The changeset says the caption "keeps its height and place" and keeps 4.5:1 "in every theme", but the backing's per-line padding takes 16px of room from every line, so a caption can wrap one line sooner (the With Caption story on a 402px phone goes from two lines to three in Matcha and Y2K, and the photo moves up 14px), and contrast is proven for the shipped themes only, so please reword it (for example "in every shipped theme, light and dark … each line gains the backing's inline padding, so a caption can grow 16px wider or wrap one line sooner") and drop "and place" from the comment at Lightbox.tsx:450, or make the height claim true in code.

Optional: captionBacking repeats counterBacking's declarations, and composing the two keeps the shared backing in one place.

[Automated review]

Comment thread .changeset/lightbox-caption-backing.md Resolved
Comment thread packages/core/src/Lightbox/Lightbox.tsx Resolved
Comment thread packages/core/src/Lightbox/Lightbox.tsx Resolved
@cixzhang
cixzhang marked this pull request as ready for review November 9, 2026 19:14
…set names the wrap and the shipped themes

The caption's span now takes the counter's backing style plus a per-line
break, so the backing lives in one place. The Changeset says the contrast
holds in every shipped theme, light and dark, and that the backing's
inline padding can make a caption 16px wider or wrap one line sooner.
@github-actions github-actions Bot removed the needs:design-review Affects visuals — Design should review label Nov 9, 2026
@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec a9d2374

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: the required build, test and docsite-test checks are deferred on this push and run before merge.

The caption backing fixes light-mode contrast: the new browser test passes in every shipped theme and Core's default tokens, light and dark, and fails on main in seven light cases. The changeset and the code comment now describe the wider caption and the possible extra wrapped line.

Optional:

  • The changeset's "16px wider" holds where --spacing-2 is 8px; Matcha and Y2K set it to 0.75rem, so each line there gains 24px, and naming the padding instead of a number keeps the note true in every theme.
  • The description's What changes bullet for Lightbox.tsx still says the caption "keeps its height and place".

[Automated review]

'@astryxdesign/core': patch
---

[fix] `Lightbox`'s caption text keeps a 4.5:1 contrast ratio in every shipped theme, light and dark. In light mode the caption's light text sat on the light translucent backdrop, as low as 2.6:1. It now sits on the same dark translucent backing as the counter, line by line; each line gains the backing's inline padding, so a caption can grow 16px wider or wrap one line sooner.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: "16px wider" holds where --spacing-2 is 8px. Matcha and Y2K set --spacing-2 to 0.75rem (matchaTheme.ts:260, y2kTheme.ts:140), so there each line gains 24px, which is also why the With Caption story wraps to a third line on a phone in those themes. A wording that holds in every theme: "each line gains the backing's inline padding at both ends, so a caption can grow wider or wrap one line sooner."

Two browser proofs found the caption by its text. With the text now on a
backing span inside the caption box, that matched the span, whose top sits
below the box's 8px top padding, so the gap read 10-12px where the box
itself still meets the photo. The proofs now measure the caption box, which
is what they assert about; the layout is unchanged.
@cixzhang
cixzhang marked this pull request as draft November 10, 2026 00:07
@cixzhang
cixzhang marked this pull request as ready for review November 10, 2026 00:07
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 33484d6

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI's required checks have not run on this head yet.

The caption backing fixes light-mode contrast: the new browser test passes in every shipped theme and Core's default tokens, light and dark, and fails on main in seven light cases. The two caption placement proofs now measure the caption box, so they pass with the backing span.

Optional:

  • The changeset's "16px wider" holds where --spacing-2 is 8px; Matcha and Y2K set it to 0.75rem, so each line there gains 24px, and naming the padding instead of a number keeps the note true in every theme.

[Automated review]

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 10, 2026
@cixzhang
cixzhang marked this pull request as draft November 11, 2026 01:07
@cixzhang
cixzhang marked this pull request as ready for review November 11, 2026 01:07

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes: one required check fails on this head.

  • Found by CI: the required lint check fails because LightboxFinePointer.a11y.browser.spec.ts:163 passes the literal hasText: 'A winding path through the forest', which @astryx/no-hardcoded-i18n-string reports as an error in CI; dialog.locator('[data-lightbox-caption]') finds the story's one caption, as the new AR9 test does, and lints clean.

The caption backing itself does what AR9 now asks: the new browser test passes in every shipped theme and Core's default tokens, light and dark, and fails on main in the seven light cases that sit under 4.5:1. Optional: the changeset's "16px wider" is 24px in Matcha and Y2K, as the earlier inline note on that line says.

Automated review (maintainer link)

// The caption's box, not its text: the text sits on a backing inside the
// box's top padding.
const caption = dialog.locator('[data-lightbox-caption]', {
hasText: 'A winding path through the forest',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found by CI: this literal fails the required lint check. @astryx/no-hardcoded-i18n-string reports hasText strings as errors in CI's strict mode, and it does not skip this file (it skips only __tests__/ and *.test.*). The zoom-with-caption story shows one caption, so this lints clean and measures the same box:

const caption = dialog.locator('[data-lightbox-caption]');

@cixzhang

Copy link
Copy Markdown
Contributor Author

(Posted by Cindy's agent.) Closing as superseded: fixed on main by #9810 and #10284. The caption sits on its backing and measures ≥4.5:1 in every shipped theme, light and dark, in Chromium and WebKit, and main's LightboxZoom interaction tests already assert the 4.5:1 caption contrast (in the band, open, over a white page and photo, and in a gallery band).

@cixzhang cixzhang closed this Nov 26, 2026
@github-actions
github-actions Bot deleted the fix/lightbox-caption-contrast branch November 27, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 33484d6d Deployed Nov 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant