Style: Stop link colours repainting block button labels - #849
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe LTR and RTL stylesheets exclude block button links from generic link colors. They add hover, focus, and active styles that use WordPress button custom properties with fallback colors. ChangesBlock button styling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized stylesheet change fixes button label contrast while preserving ordinary link styling and adding button interaction states. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
The link rules in wp4.css are more specific than the button colours the
block theme emits. Core emits
:root :where( .wp-block-button .wp-block-button__link )
which is specificity (0,1,0), because :where() adds nothing. The link
rules `a:link`, `a:visited` and `a:hover` are (0,1,1), so they win and
repaint button labels with the body link colour while the button keeps
its own background.
On Planet that renders #21759b on #3858e9, a contrast ratio of 1.09:1,
and #d54e21 on #3858e9 on hover, 1.32:1.
Guard the three link rules with :where( :not( .wp-element-button ) ),
which leaves their specificity unchanged so nothing else in the cascade
moves, and is the same idiom core already uses for
:root :where( a:where( :not( .wp-element-button ) ):hover ).
Excluding buttons from a:hover also removes the only hover feedback
Planet had, so add the hover, focus and active states from the button
custom properties the wporg parent theme already defines. Pages that
load the parent theme's button stylesheet are unaffected: those rules
are (0,2,0) and load later.
Measured on planet.wordpress.org:
rest #ffffff on #3858e9 5.61:1 (was 1.09:1)
hover #ffffff on #213fd4 7.70:1 (was 1.32:1)
active #ffffff on #1e1e1e 16.67:1
The hover result matches wordpress.org/download/, which does not load
wp4.css and gets these states from the parent theme.
Ordinary links are untouched: 1,335 non-button links on the Planet front
page keep #21759b, and the search icon button is unchanged.
See https://meta.trac.wordpress.org/ticket/8418
fa7d2e9 to
cdae1af
Compare
|
@softglazee Thanks for looking into this and creating the PR! The changes look good. |
|
Thanks again for preparing the fix. Since this PR addresses the issue I identified in Meta Trac #8418, could I please be included in the props when it is merged, if applicable? |
Trac ticket: https://meta.trac.wordpress.org/ticket/8418
The problem
Buttons on https://planet.wordpress.org/ render their label in the body link colour on top of the button's own background, so the label is close to invisible.
#21759bon#3858e9#d54e21on#3858e9#4ca6cfon#3858e9Why it happens
The block theme emits its button colours through global styles:
That selector is specificity (0,1,0) —
:rootis the only thing that counts,:where()adds nothing.The link rules in
wp4.cssare (0,1,1):So the link colour wins on
colorwhile the button keeps its ownbackground-color. The custom properties are fine,--wp--custom--button--color--textresolves to#ffffff; they are simply being overridden.a:hoveranda:visitedhave always been (0,1,1), so those two states have been wrong for a while. The rest state broke whena:linkwas added alongsidea:aon its own is (0,0,1), which loses to the button rule.wp4-rtl.csshas not been regenerated since that change, which is why it still has a bareaand why the rest state still looks correct in RTL.The change
Guard the three link rules with
:where( :not( .wp-element-button ) ).:where()contributes zero specificity, so (0,1,1) and (0,0,1) are unchanged and nothing else in the cascade shifts; only the match set narrows. This is the idiom core already uses on the same pages, for example:root :where( a:where( :not( .wp-element-button ) ):hover ).Excluding buttons from
a:hoveralso removes the only hover feedback Planet had, so this adds the hover, focus and active states from the button custom properties the wporg parent theme already defines. Pages that load the parent theme's button stylesheet are unaffected: those rules are[class*="wp-block"] .wp-block-button__link:hoverat (0,2,0) and load afterwp4.css.The same change is applied to
wp4-rtl.css, which is generated bygrunt css. That file already looks out of date relative towp4.css, so this PR makes the equivalent change rather than regenerating it, to keep the diff reviewable.Testing
Measured on https://planet.wordpress.org/ with
wp4.cssswapped for the patched file at the same position in the cascade.#21759bon#3858e9, 1.09:1#ffffffon#3858e9, 5.61:1#d54e21on#3858e9, 1.32:1#ffffffon#213fd4, 7.70:1#ffffffon#1e1e1e, 16.67:1The hover result matches https://wordpress.org/download/, which does not load
wp4.cssand gets these states from the parent theme.No regressions found on the Planet front page:
#21759b. The full link colour census is identical before and after.rgb(30, 30, 30).Steps to reproduce the original bug
Screenshots of the before and after states are on the Trac ticket.
Summary by CodeRabbit