Skip to content

Toolbar: Keep the pressed and focus indicator square - #86855

Merged
t-hamano merged 9 commits into
trunkfrom
fix/toolbar-button-pseudo-width
Nov 18, 2026
Merged

t-hamano merged 9 commits into
trunkfrom
fix/toolbar-button-pseudo-width

Conversation

@t-hamano

@t-hamano t-hamano commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What?

Restores the 32x32 square for the pressed background and focus ring of toolbar buttons, which are currently 30x32.

before-after-toolbar-default

Why?

#79982 improved the secondary variant of Button by drawing its outline with a real border, and reserved a 1px transparent border on every variant so that all variants share the same box size. To keep small icon buttons square despite this border, it also applied a negative inline margin to the icon (see #79982 (comment) for details).

As a side effect, the padding box of every button became 2px narrower. The negative margin restores the button's own width, but not the ::before of toolbar buttons: its left/right offsets are measured from the padding box, so the pressed background and focus ring of toolbar buttons shrank from 32x32 to 30x32.

This only happens in the toolbar: a regular Button draws its focus ring with an outline on the element itself, while toolbar buttons draw the pressed background and focus ring on an absolutely positioned ::before, whose size depends on the padding box.

How?

Subtract $border-width from the ::before offsets where they are defined, in Toolbar / ToolbarGroup. The fix belongs there because the toolbar owns this ::before treatment.

Ideally, the toolbar would use the design system's outline-based focus ring like other buttons, and this problem would not exist in the first place. However, the toolbar's button styles are heavily customized, so that is not something we can do right now.

Testing Instructions

  1. Run Storybook and open Components > Toolbar > Default.
  2. Inspect the Bold button (pressed) and confirm its ::before is 32x32.
  3. Repeat with the "Without Group" story.
  4. Open Block Editor > BlockMover and confirm the focus ring is not clipped and looks the same as on trunk.
  5. In the block editor, select a paragraph and toggle Bold; the pressed background should be square.

Testing Instructions for Keyboard

  1. Tab into the block toolbar and move between buttons with the arrow keys.
  2. Confirm the focus ring is square (32x32).

Use of AI Tools

This PR was investigated and authored with Claude Code, and reviewed by me.

claude and others added 2 commits November 15, 2026 07:41
The 1px transparent border reserved on every Button shrank the toolbar
button's ::before (which paints the pressed background and the focus
ring) from 32x32 to 30x32, because absolutely positioned offsets are
measured from the padding box. Subtract the border width from the
left/right offsets so the indicator is square again.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URw1rqvJyd3rrDFo5ST
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URw1rqvJyd3rrDFo5ST
@github-actions github-actions Bot added the [Package] Components /packages/components label Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +55 B (0%)

Total Size: 8.66 MB

📦 View Changed
Filename Size Change
build/styles/block-editor/style-rtl.css 20.1 kB +12 B (+0.06%)
build/styles/block-editor/style-rtl.min.css 17.1 kB +13 B (+0.08%)
build/styles/block-editor/style.css 20.1 kB +11 B (+0.05%)
build/styles/block-editor/style.min.css 17 kB +12 B (+0.07%)
build/styles/components/style-rtl.css 18.1 kB +3 B (+0.02%)
build/styles/components/style-rtl.min.css 15.2 kB -1 B (-0.01%)
build/styles/components/style.css 18.1 kB +2 B (+0.01%)
build/styles/components/style.min.css 15.2 kB +3 B (+0.02%)

87c568c Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 3ec3fe4 trunk % Change
timeToFirstByte 36.1 ms +17.45% -4.02% 36.1 ms +9.28% -6.65% 0%
largestContentfulPaint 64 ms +0% -9.38% 60 ms +6.67% -6.67% 6.67%
lcpMinusTtfb 24.05 ms +10.6% -8.73% 22.7 ms +17.62% -7.49% 5.95%
wpBeforeTemplate 18.99 ms +7.21% -1% 18.48 ms +13.2% -3.41% 2.76%
wpTemplate 13.76 ms +9.52% -4.58% 13.61 ms +5.73% -6.39% 1.1%
wpTotal 33.1 ms +13.38% -4.2% 32.95 ms +9.29% -6.49% 0.46%
wpMemoryUsage 7.75 MB +0% -0% 7.71 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 3ec3fe4 trunk % Change
timeToFirstByte 30.2 ms +14.07% -1.66% 30.25 ms +6.28% -2.48% -0.17%
largestContentfulPaint 56 ms +7.14% -0% 56 ms +0% -0% 0%
lcpMinusTtfb 26.2 ms +1.72% -3.24% 25.75 ms +2.91% -7.18% 1.75%
wpBeforeTemplate 16.68 ms +16.19% -1.5% 16.35 ms +6.18% -1.71% 2.02%
wpTemplate 10.83 ms +3.32% -2.12% 10.74 ms +3.91% -5.21% 0.84%
wpTotal 27.39 ms +13% -0.88% 27.61 ms +3.91% -3.15% -0.8%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 3ec3fe4 trunk % Change
mediaProcessingJpeg 219.6 ms +1.47% -0.73% 221.98 ms +1.15% -2.54% -1.07%
mediaProcessingAvif 3788.7 ms +0.69% -0.56% 3570.99 ms +2.59% -0.51% 6.1%
mediaProcessingJpegToAvif 2527.81 ms +1% -0.33% 2502.16 ms +0.14% -0.27% 1.03%

media-upload

Metric 3ec3fe4 trunk % Change
jpegUploadProcessing 1435.34 ms +2.92% -0.85% 1440.54 ms +1.31% -0.15% -0.36%
pngUploadProcessing 197.26 ms +10.51% -4.27% 203.05 ms +2.36% -8.66% -2.85%
largeJpegUploadProcessing 1436.5 ms +1.43% -0.41% 1459.99 ms +0.54% -1.49% -1.61%
multipleImageUploadProcessing 1492.95 ms +0.45% -0.17% 1493.55 ms +1.51% -0.75% -0.04%

post-editor

Metric 3ec3fe4 trunk % Change
serverResponse 331.78 ms +3.7% -9.9% 308.32 ms +7.51% -3.67% 7.61%
firstPaint 348.75 ms +6.84% -6.09% 333.01 ms +1.73% -2.83% 4.73%
domContentLoaded 681.45 ms +2.58% -2.3% 660.93 ms +1.37% -0.93% 3.1%
loaded 682.5 ms +2.58% -2.31% 661.9 ms +1.39% -0.91% 3.11%
firstContentfulPaint 387.3 ms +4.54% -3.8% 370.66 ms +3.69% -2.43% 4.49%
firstBlock 1796.73 ms +7.61% -1.05% 1746.1 ms +3.04% -0.88% 2.9%
type 16.69 ms +10.55% -9.59% 16.82 ms +6.42% -10.4% -0.77%
typeWithoutInspector 16.1 ms +6.71% -7.14% 17.65 ms +4.19% -8.78% -8.78%
typeWithTopToolbar 22.47 ms +3.74% -8.63% 23.97 ms +3.05% -1.84% -6.26%
typeContainer 8.04 ms +6.72% -18.16% 7.62 ms +10.89% -10.5% 5.51%
focus 94.99 ms +6.07% -1.11% 109.1 ms +3.66% -4.14% -12.93%
firstFocus 220.86 ms +0% -0% 230.79 ms +0% -0% -4.3%
selectAll 334.48 ms +7.95% -2.6% 336.77 ms +2.73% -2% -0.68%
undo 25.69 ms +9.81% -0.43% 26.49 ms +9.4% -2.87% -3.02%
listViewOpen 67.92 ms +5.85% -7.32% 66.33 ms +3.05% -7.96% 2.4%
inserterOpen 37.33 ms +7.63% -5.87% 38.16 ms +4.93% -4.61% -2.18%
inserterHover 10.09 ms +11.1% -9.42% 9.86 ms +10.14% -7.71% 2.33%
inserterSearch 7.36 ms +10.73% -7.88% 6.99 ms +6.87% -0.57% 5.29%
loadPatterns 538.87 ms +3.85% -4.33% 552.05 ms +6.46% -4.54% -2.39%
wpTotal 323.05 ms +3.71% -10.18% 299.5 ms +7.8% -3.7% 7.86%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 3ec3fe4 trunk % Change
serverResponse 294.95 ms +5.82% -5.1% 308.49 ms +1.76% -9.24% -4.39%
firstPaint 314.78 ms +18.33% -3.31% 311.65 ms +16.13% -3.47% 1%
domContentLoaded 644.49 ms +4.02% -1.42% 638.94 ms +0.95% -0.55% 0.87%
loaded 645.17 ms +4.03% -1.39% 639.66 ms +0.97% -0.55% 0.86%
firstContentfulPaint 368.09 ms +7.76% -0.98% 362.31 ms +0.65% -0.58% 1.6%
firstBlock 1961.79 ms +1.18% -1.23% 1955.82 ms +0.65% -0.54% 0.31%
type 14.05 ms +6.9% -6.33% 14.29 ms +6.02% -8.26% -1.68%
navigate 91.03 ms +1.97% -4.03% 95.26 ms +3.73% -6.36% -4.44%
loadPatterns 1053.11 ms +4.03% -4.78% 1035.16 ms +3.69% -11.45% 1.73%
loadPages 998.25 ms +0.87% -0.55% 987.29 ms +0.88% -1.08% 1.11%
wpTotal 286.7 ms +6% -5.29% 300.24 ms +1.8% -9.51% -4.51%
wpMemoryUsage 12.82 MB +0% -0% 12.79 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

87c568c Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

should apply a named font size using the font size buttons in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"large"} -->
+ <!-- wp:paragraph {"fontSize":"medium"} -->
- <p class="has-large-font-size">Paragraph to be made "large"</p>
+ <p class="has-medium-font-size">Paragraph to be made "large"</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:153:6
should reset a named font size using input field in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"small"} -->
+ <!-- wp:paragraph {"fontSize":"tiny"} -->
- <p class="has-small-font-size">Paragraph with font size reset using input field</p>
+ <p class="has-tiny-font-size">Paragraph with font size reset using input field</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:216:6
should reset a named font size using the tools panel menu in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"medium"} -->
+ <!-- wp:paragraph {"fontSize":"small"} -->
- <p class="has-medium-font-size">Paragraph with font size reset using tools panel menu</p>
+ <p class="has-small-font-size">Paragraph with font size reset using tools panel menu</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:178:6
should select synced pattern in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]') with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
    14 × locator resolved to <div tabindex="0" role="document" draggable="true" data-title="Pattern" data-type="core/block" data-is-drop-zone="true" aria-label="Block: Pattern" id="block-c53bc504-3c34-4968-b988-51531c505a7f" data-block="c53bc504-3c34-4968-b988-51531c505a7f" class="block-editor-block-list__block wp-block is-selected is-reusable block-library-block__reusable-block-container wp-block-block block-editor-block-list__layout">…</div>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:1464:5

87c568c Run

@t-hamano t-hamano self-assigned this Nov 15, 2026
@t-hamano t-hamano added the [Type] Bug An existing feature does not function as intended label Nov 15, 2026
The ::before height of the vertical mover buttons is measured from the
padding box, so the 1px reserved Button border shrank it from 16px to
14px. Add the border back.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URw1rqvJyd3rrDFo5ST
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Nov 15, 2026
The mover buttons clip their overflow, so enlarging their ::before
cuts off the focus ring. Revert the height change and keep the
original 2px inset instead of following the toolbar group's offsets.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URw1rqvJyd3rrDFo5ST
t-hamano and others added 2 commits November 17, 2026 11:35
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URw1rqvJyd3rrDFo5ST
Comment on lines +105 to +110
// Keep the focus ring inset enough to stay visible instead of following
// the toolbar group's offsets. Matches the toolbar group's specificity.
&.has-icon.has-icon::before {
left: 2px;
right: 2px;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This override is needed because the block mover buttons clip their overflow. overflow: hidden was added in #67261 to prevent misclicks.

Without this override, the focus ring sits too close to the button's edge, so its sides and rounded corners get clipped.

mover-with-without-override

@t-hamano
t-hamano marked this pull request as ready for review November 17, 2026 04:27
@t-hamano
t-hamano requested review from a team and ellatrix as code owners November 17, 2026 04:27
@github-actions
github-actions Bot requested review from aduth and ciampo November 17, 2026 04:28
Comment thread packages/components/CHANGELOG.md Resolved
@t-hamano
t-hamano merged commit eeecc67 into trunk Nov 18, 2026
85 checks passed
@t-hamano
t-hamano deleted the fix/toolbar-button-pseudo-width branch November 18, 2026 01:32
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 18, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
* Toolbar: Keep the pressed and focus indicator square

The 1px transparent border reserved on every Button shrank the toolbar
button's ::before (which paints the pressed background and the focus
ring) from 32x32 to 30x32, because absolutely positioned offsets are
measured from the padding box. Subtract the border width from the
left/right offsets so the indicator is square again.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URw1rqvJyd3rrDFo5ST

* Add changelog entry

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URw1rqvJyd3rrDFo5ST

* Block Mover: Keep the vertical focus indicator height

The ::before height of the vertical mover buttons is measured from the
padding box, so the 1px reserved Button border shrank it from 16px to
14px. Add the border back.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URw1rqvJyd3rrDFo5ST

* Block Mover: Keep the focus ring visible inside clipped buttons

The mover buttons clip their overflow, so enlarging their ::before
cuts off the focus ring. Revert the height change and keep the
original 2px inset instead of following the toolbar group's offsets.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URw1rqvJyd3rrDFo5ST

* Nest the block mover focus ring offsets into the button rule

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URw1rqvJyd3rrDFo5ST

* Update changelog entry

Co-authored-by: Lena Morita <lena@jaguchi.com>

---------

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Package] Components /packages/components [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants