close
Skip to content

[2.x] fix: use luma-based text colour for primary buttons to ensure contrast#4451

Merged
imorland merged 2 commits into2.xfrom
im/fix-4440-button-primary-contrast
Mar 15, 2026
Merged

[2.x] fix: use luma-based text colour for primary buttons to ensure contrast#4451
imorland merged 2 commits into2.xfrom
im/fix-4440-button-primary-contrast

Conversation

@imorland
Copy link
Copy Markdown
Member

Summary

  • The primary button text colour was hardcoded to the page background colour, which fails when the primary colour is dark — producing near-black text on a dark button background (visible in both dark mode and high contrast mode)
  • Replaces the static colour with if(luma(@primary-color) > 50%, @text-on-light, @text-on-dark), picking text colour based on the perceptual luminance of the primary colour — the same logic already used by the JS textContrastClass / isDark helpers
  • Removes the now-redundant button-primary override from the HC block (the base .scheme() mixin now handles it correctly for all themes)
  • Adds Jest unit tests for the previously untested isDark and textContrastClass utilities

Fixes #4440

Test plan

  • Jest tests pass (yarn test)
  • Set primary colour to a dark value (e.g. #064635) in Admin → Appearance — button text should be white in all themes including Light/Dark High Contrast
  • Set primary colour to a light value (e.g. #E8D8B0) — button text should be dark
  • Default primary (#536F90) continues to show white button text

🤖 Generated with Claude Code

imorland and others added 2 commits March 15, 2026 07:07
…ontrast

The button-primary text colour was hardcoded to the page background
colour, which fails when the primary colour is dark (e.g. dark green
#064635 in high contrast mode produces near-black text on dark bg).

Replace the static colour with an if/luma check that picks dark or
light text based on the perceptual luminance of the primary colour,
matching the same logic already used by the JS textContrastClass
helper. Also removes the now-redundant override in the HC block.

Fixes #4440

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
These utilities implement the same contrast logic as the LESS luma()
fix in root.less (issue #4440) and had no test coverage.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@imorland imorland changed the title fix(less): use luma-based text colour for primary buttons to ensure contrast [2.x] fix: use luma-based text colour for primary buttons to ensure contrast Mar 15, 2026
@imorland imorland added this to the 2.0.0-beta.8 milestone Mar 15, 2026
@imorland imorland marked this pull request as ready for review March 15, 2026 07:22
@imorland imorland requested a review from a team as a code owner March 15, 2026 07:22
@imorland imorland merged commit 8e4046c into 2.x Mar 15, 2026
27 checks passed
@imorland imorland deleted the im/fix-4440-button-primary-contrast branch March 15, 2026 07:22
@imorland imorland mentioned this pull request Mar 21, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.x] Some primary colors lack contrast on buttons in high contrast mode

1 participant