Button: hide focus outline on :active for click feedback in forced-colors mode#76833
Button: hide focus outline on :active for click feedback in forced-colors mode#76833
Conversation
e654b2b to
dbe1f02
Compare
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +33 B (0%) Total Size: 7.73 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in da757e6. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23651745299
|
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR!
It appears this PR re-exposes an issue we previously fixed in #75346. Specifically, the default outline is displayed when the focus and active states are combined:
5866d7bc366d4b73d885e20e1dbdf7d7.mp4
As an alternative approach, does this code work?
&:focus:active {
outline: none;
}d5c4d55e86a46fe04986a709de51a802.mp4
…lors mode Made-with: Cursor
07791ab to
da757e6
Compare
Thank you for reviewing. I swear I tested for that specific regression, but for some reason, I must have missed it. I applied your suggestion. |
t-hamano
left a comment
There was a problem hiding this comment.
LGTM! I believe this change only affects the forced-colors mode.
|
@t-hamano worth backporting this one too? |
…lors mode (#76833) Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
|
@ciampo, I think this PR should not be backported as it is a feature enhancement and does not fix any bugs or regressions that first appeared in the 7.0 release. |
What?
Follow up to #76719.
Hide the focus
outlineduring:activestate on theButtoncomponent to provide visual click feedback in forced-colors (High Contrast) mode.Why?
In forced-colors mode,
box-shadowis not rendered — theoutlineis the only visible focus indicator. Without hiding it on:active, clicking a focused button produces no visual feedback (discussed here).How?
Added a single
&:focus:active { outline: none; }rule after the.is-pressedblock.This approach was suggested by @t-hamano as a simpler alternative to the original
&:focus:not(:active)approach, which re-exposed a regression from #75346 (the default browser outline would appear during the:focus:activestate, since no outline rule covered it).Implementation details
Why
&:focus:activeinstead of&:focus:not(:active)?With
&:focus:not(:active), the:focus:activestate has no outline rule covering it, so the browser's default outline leaks through — the exact issue fixed in #75346.With
&:focus:active { outline: none; }, the existing&:focus { outline: 3px solid transparent; }rule remains untouched, and the new rule explicitly removes the outline only during the click. No gaps in coverage.Specificity
&:focus:activecompiles to.components-button:focus:activewith specificity0,3,0, which:&:focus(0,2,0) and variant outline declarations like.is-primary(0,2,0), so it naturally overrides them..is-pressed &:focus(0,3,0), but wins by source order since it's placed after the.is-pressedblock.Comparison with
@wordpress/uiButtonThe
@wordpress/uiButton already uses:focus:not(:active)for its outline via the sharedoutset-ring--focus-except-activeutility class. After this change, both buttons have the same visual behavior: the focus indicator hides on:activefor click feedback in all modes.Testing Instructions
npm run storybook:dev)forced-colors: active):focus:activestate (the issue from Button: prevent outline flicker when focused and active at the same time #75346)Testing Instructions for Keyboard
Screenshots or screencast
Kapture.2026-03-27.at.15.45.44.mp4
Use of AI Tools
Cursor + Claude Opus 4.6