Button: Hide focus style when :active#74106
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 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: +6 B (0%) Total Size: 2.58 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in e97ee6b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20339581266
|
|
I share the motivation, and if this PR fixes it, 👍 👍, but want to just throw the question into the mix: would |
|
|
||
| // Focus. | ||
| // See https://github.com/WordPress/gutenberg/issues/13267 for more context on these selectors. | ||
| &:focus:not(:disabled) { |
There was a problem hiding this comment.
I believe these disabled selectors were unnecessary. Disabled elements won't get focused to begin with.
Mmm, we've considered it (#65088) in depth, but there are downsides to that approach that gives us pause. The |
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Thanks for this @mirka 👍
✅ The current approach addresses the flicker issue as advertised
✅ :not(:active) is the better choice with accessibility concerns around :focus-visible outweighing slight UX benefit
LGTM 🚢
Screen.Recording.2025-12-18.at.11.04.07.am.mp4
I think I found a downside – at least with the implementation since this PR. In Chrome and Safari, this has allowed the native outlines to show when activating buttons with Space.
I wasn’t able to reproduce that after reverse applying the code change from this PR: git show 7793dffec75765abde5068262f98d32a8e2fcd61 packages/components/src/button/style.scss | git apply -RI imagine this can be fixed by separating the Other than that, for consistency, it looks like the toolbar styles should get similar treatment. block-toolbar-active.mp4Here’s one spot, for instance: gutenberg/packages/components/src/toolbar/toolbar/style.scss Lines 90 to 92 in bb514ac One last thing, is that sometimes the flicker still happens although more faintly. You can actually see it in the screen recording posted by Aaron above. That particular button is also where it seems mostly likely to happen oddly enough. On my machine, Firefox is the most likely browser to have that happen. I am not sure I’ve seen it in Chrome or Safari outside of that aforementioned particular button. I’ve only encountered this in the editor as well – though I’ve tested less in Storybook, I haven’t seen it happen there. |
I opened #75346 with a fix, which hopefully will also tackle the "Firefox in the editor" flicker 🤞 I tried to apply a similiar fix to the toolbar styles click to expanddiff --git i/packages/components/src/toolbar/toolbar/style.scss w/packages/components/src/toolbar/toolbar/style.scss
index 988d5f5d12f..49539ef7d2e 100644
--- i/packages/components/src/toolbar/toolbar/style.scss
+++ w/packages/components/src/toolbar/toolbar/style.scss
@@ -87,9 +87,13 @@
}
// Focus style.
- &:focus::before {
+ &:focus:not(:active)::before {
@include block-toolbar-button-style__focus();
}
+ &:focus::before {
+ // Windows High Contrast mode will show this outline, but not the box-shadow.
+ outline: 2px solid transparent;
+ }
// Ensure the icon buttons remain square.
// This needs specificity.but there is a noticeable flicker when opening dropdowns from the toolbar, potentially caused by some browser timing , where the key may be released (ie. the The only fix that comes to mind is to apply a delay to the appearance of the box shadow. |
What?
Hides the focus styles on
Buttonwhen:active.Why?
Prevent a flickering focus ring when clicking a button that triggers e.g. a modal or dropdown, taking away the focus immediately.
Testing Instructions
Try the interaction in components like
DropdownMenuorMenu.Should not introduce any accessibility concerns.
Screenshots or screencast
Before
CleanShot.2025-12-18.at.22-58-08.mp4
After
CleanShot.2025-12-18.at.22-58-30.mov