Skip to content

fix(Avatar): use light-dark() for fallback initials to pass WCAG AA contrast in dark mode - #5321

Open
Abidit wants to merge 2 commits into
facebook:mainfrom
Abidit:fix/avatar-fallback-dark-mode-contrast
Open

fix(Avatar): use light-dark() for fallback initials to pass WCAG AA contrast in dark mode#5321
Abidit wants to merge 2 commits into
facebook:mainfrom
Abidit:fix/avatar-fallback-dark-mode-contrast

Conversation

@Abidit

@Abidit Abidit commented Aug 22, 2026

Copy link
Copy Markdown

Summary

Fixes #5279

Avatar's fallback initials (shown when no image is set) used
--color-text-secondary on --color-neutral background, which
fails WCAG AA contrast (4.5:1) in dark mode at 4.27:1.

Fix

Switch to light-dark() so each color mode gets the appropriate
text color:

  • Light mode: --color-text-secondary → 5.42:1 ✅ (unchanged)
  • Dark mode: --color-text-primary → 7.25:1 ✅ (was 4.27:1 ❌)

This matches the existing convention in useTableStickyColumns.tsx.

Change

One line changed in Avatar.tsx:

- color: colorVars['--color-text-secondary'],
+ color: 'light-dark(var(--color-text-secondary), var(--color-text-primary))',

…ontrast in dark mode

Fallback initials used --color-text-secondary on --color-neutral which
fails WCAG AA (4.5:1) in dark mode at 4.27:1. Switch to light-dark()
so dark mode uses --color-text-primary (7.25:1) while light mode keeps
--color-text-secondary (5.42:1), matching the existing convention in
useTableStickyColumns.tsx.

Fixes facebook#5279
@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 22, 2026 5:28am

Request Review

@meta-cla

meta-cla Bot commented Aug 22, 2026

Copy link
Copy Markdown

Hi @Abidit!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Aug 22, 2026
@meta-cla

meta-cla Bot commented Aug 22, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

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

meta-cla Bot commented Aug 22, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@Abhirup0

Copy link
Copy Markdown

Hi @Abidit! Nice catch and thank you for putting up this fix!

Using light-dark() is definitely the right solution here — it fixes the dark mode contrast violation (7.25:1, passing WCAG AA) while keeping the light mode secondary look intact (5.42:1).

Just a few small things that might help get this PR merge-ready:

  1. Changeset:
    Astryx requires a changeset for packages that get published so CI can pass (check:changesets). You can add a file like .changeset/avatar-fallback-dark-contrast.md with:

'@astryxdesign/core': patch

[fix] Avatar: resolve fallback initials and default icon color via light-dark() to meet WCAG AA contrast in dark mode (#5279)
@Abidit

  1. Token variable reference:
    In Avatar.tsx, styles typically use the imported colorVars tokens directly rather than raw CSS strings:
color: `light-dark(${colorVars['--color-text-secondary']}, ${colorVars['--color-text-primary']})`,
  1. Regression tests:
    Adding a quick unit test in Avatar.test.tsx checking that fallback initials satisfy WCAG AA contrast in both light and dark modes will help make sure this doesn't regress in the future.

  2. (Bonus / Optional) AvatarGroupOverflow:
    packages/core/src/AvatarGroup/AvatarGroupOverflow.tsx (the +N count indicator) uses the exact same --color-neutral background and has the same dark mode text color. Updating it here would make the whole Avatar family fully WCAG AA compliant!

- Use colorVars token references instead of raw CSS strings
- Add WCAG AA contrast regression tests for Avatar and AvatarGroupOverflow
- Fix AvatarGroupOverflow +N indicator with same light-dark() approach
- Add changeset for patch release
@Abidit

Abidit commented Aug 22, 2026

Copy link
Copy Markdown
Author

**Abhirup0 **

Thanks for the detailed review! I've addressed all four points:

  1. Changeset added
  2. Switched to colorVars token references
  3. Added regression tests for both Avatar and AvatarGroupOverflow
  4. Fixed AvatarGroupOverflow +N indicator with the same light-dark() approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avatar fallback initials fail WCAG AA contrast in dark mode (--color-text-secondary on --color-neutral)

2 participants