[2.x] fix: use luma-based text colour for primary buttons to ensure contrast#4451
Merged
[2.x] fix: use luma-based text colour for primary buttons to ensure contrast#4451
Conversation
…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>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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 JStextContrastClass/isDarkhelpersbutton-primaryoverride from the HC block (the base.scheme()mixin now handles it correctly for all themes)isDarkandtextContrastClassutilitiesFixes #4440
Test plan
yarn test)#064635) in Admin → Appearance — button text should be white in all themes including Light/Dark High Contrast#E8D8B0) — button text should be dark#536F90) continues to show white button text🤖 Generated with Claude Code