Skip to content

Components: Show pressed state of Button and Toolbar in forced colors mode - #86393

Merged
mirka merged 5 commits into
trunkfrom
components-forced-colors-pressed-state
Nov 9, 2026
Merged

mirka merged 5 commits into
trunkfrom
components-forced-colors-pressed-state

Conversation

@mirka

@mirka mirka commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

What?

Follow-up to #85948.

Makes the pressed state of the @wordpress/components Button and toolbar buttons visible in forced colors mode, for every variant and for disabled pressed buttons. Also keeps the check mark on selected color swatches visible, which is what marks the selection there.

Why?

The pressed state is conveyed only by background and foreground color. Forced colors mode replaces both with system colors, so a pressed toggle looks the same as an unpressed one. This includes the common editor toggles, such as Bold in the block toolbar and the List View toggle in the document tools.

How?

This uses the same system selection colors as #85948, but with !important, because opting out of color adjustment lets every other color rule that matches the button take effect, including the variants' high-specificity state rules and consumers' own pressed styles. Toolbar buttons fill their ::before instead, so the document tools headers, which hide it, restore the fill on the button itself. CircularOptionPicker options opt back in, because they paint their swatch with a box-shadow and mark selection with a check mark, which now uses a system color because forced colors replace the swatch it was chosen to contrast with.

Testing Instructions

  1. Run Storybook and open Components / @wordpress-components / Actions / Button / Default.
  2. In Chrome DevTools, open Rendering and set "Emulate CSS media feature forced-colors" to active.
  3. In Controls, turn on isPressed and confirm the button is filled with the selection color and its label is readable.
  4. Turn on disabled and confirm the button is filled with the gray disabled color and its label is readable.
  5. Change variant and confirm the same for each variant.
  6. Open a post, add a Paragraph block with bold text, and place the cursor in the bold text.
  7. Confirm that Bold in the block toolbar is filled with the selection color, with no dark box behind the icon.
  8. Toggle the block inserter and Document Overview, and confirm each toggle is filled while it is open.
  9. On a site with a classic theme, confirm the same for the block inserter in Appearance > Widgets and in the Customizer's widget areas.
  10. In Storybook, open Components / @wordpress-components / Selection & Input / Color / ColorPalette / Default, select a dark swatch and a light swatch, and confirm the check mark is visible on both.
  11. Set "Emulate CSS media feature prefers-color-scheme" to dark and repeat.
  12. Turn off forced colors emulation and confirm the buttons look unchanged.

Testing Instructions for Keyboard

  1. With forced colors emulation active, select bold text and press Alt+F10 to move focus to the block toolbar.
  2. Use the arrow keys to move to Bold, and confirm a focus ring is visible around its fill.
  3. Press Tab or Shift+Tab to reach the Document Overview toggle while it is open, and confirm a focus ring is visible around it.

Screenshots or screencast

Before After
Forced colors Unpressed, pressed, and pressed disabled buttons of every variant, and a toolbar, where pressed and unpressed look the same Pressed buttons and toolbar buttons are filled with the selection color, and disabled pressed ones with gray
Forced colors, dark Unpressed, pressed, and pressed disabled buttons of every variant, and a toolbar, where pressed and unpressed look the same, in dark Pressed buttons and toolbar buttons are filled with the selection color, and disabled pressed ones with gray, in dark
Editor block toolbar, Bold pressed Block toolbar where Bold looks the same as Italic Block toolbar where Bold is filled with the selection color
Editor block toolbar, dark Dark block toolbar where Bold looks the same as Italic Dark block toolbar where Bold is filled with the selection color
Document tools, List View open Document tools where the List View toggle looks unpressed Document tools where the List View toggle is filled with the selection color
Document tools, dark Dark document tools where the List View toggle has only a colored border Dark document tools where the List View toggle is filled with the selection color
Bold focused Focused Bold button with a visible focus ring around its fill
Bold focused, dark Focused Bold button with a visible focus ring around its fill, in dark
Color swatches, dark and light swatch selected The check mark is missing on the selected dark swatches Every selected swatch shows a check mark
Color swatches, dark The check mark is missing on the selected light swatches, in dark Every selected swatch shows a check mark, in dark
Normal colors (unchanged) Buttons and toolbar in normal colors before Buttons and toolbar in normal colors after, identical to before

…lors mode

Forced colors discard the colors that mark a pressed button, so a pressed
toggle looks the same as an unpressed one. Fill pressed buttons with the
system selection colors, following the `@wordpress/ui` Button.
@mirka mirka added the [Type] Bug An existing feature does not function as intended label Nov 5, 2026
@mirka mirka self-assigned this Nov 5, 2026
@github-actions github-actions Bot added [Package] Components /packages/components [Package] Editor /packages/editor [Package] Edit Widgets /packages/edit-widgets labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 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: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@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: +1.45 kB (+0.02%)

Total Size: 8.63 MB

📦 View Changed
Filename Size Change
build/styles/components/style-rtl.css 17.8 kB +222 B (+1.26%)
build/styles/components/style-rtl.min.css 14.9 kB +168 B (+1.14%)
build/styles/components/style.css 17.9 kB +222 B (+1.26%)
build/styles/components/style.min.css 14.9 kB +169 B (+1.15%)
build/styles/customize-widgets/style-rtl.css 2.92 kB +39 B (+1.35%)
build/styles/customize-widgets/style-rtl.min.css 1.9 kB +28 B (+1.5%)
build/styles/customize-widgets/style.css 2.92 kB +40 B (+1.39%)
build/styles/customize-widgets/style.min.css 1.9 kB +29 B (+1.55%)
build/styles/edit-widgets/style-rtl.css 5.32 kB +84 B (+1.6%)
build/styles/edit-widgets/style-rtl.min.css 3.91 kB +75 B (+1.96%)
build/styles/edit-widgets/style.css 5.32 kB +84 B (+1.61%)
build/styles/edit-widgets/style.min.css 3.91 kB +75 B (+1.96%)
build/styles/editor/style-rtl.css 31.4 kB +58 B (+0.18%)
build/styles/editor/style-rtl.min.css 27.2 kB +48 B (+0.18%)
build/styles/editor/style.css 31.5 kB +57 B (+0.18%)
build/styles/editor/style.min.css 27.2 kB +47 B (+0.17%)

33c2bf0 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 778056c trunk % Change
timeToFirstByte 54.5 ms +3.67% -3.49% 55.4 ms +8.39% -4.06% -1.62%
largestContentfulPaint 92 ms +4.35% -4.35% 88 ms +9.09% -4.55% 4.55%
lcpMinusTtfb 35.5 ms +12.54% -5.49% 32.95 ms +5.61% -3.19% 7.74%
wpBeforeTemplate 28.73 ms +1.91% -2.47% 28.58 ms +2.9% -0.77% 0.52%
wpTemplate 21.86 ms +3.66% -5.22% 22.13 ms +4.97% -4.61% -1.22%
wpTotal 50.81 ms +3.64% -3.74% 51.38 ms +8.95% -3.81% -1.11%
wpMemoryUsage 7.72 MB +0% -0% 7.69 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 778056c trunk % Change
timeToFirstByte 46.6 ms +5.47% -3.76% 45.85 ms +7.09% -2.29% 1.64%
largestContentfulPaint 100 ms +4% -4% 100 ms +2% -4% 0%
lcpMinusTtfb 52.95 ms +5.1% -1.79% 52.7 ms +3.13% -2.56% 0.47%
wpBeforeTemplate 26.35 ms +5.35% -1.67% 26.13 ms +7.58% -1.3% 0.84%
wpTemplate 16.24 ms +7.02% -4.25% 16.25 ms +2.46% -2.83% -0.06%
wpTotal 43.36 ms +6.13% -3.78% 42.82 ms +7.47% -2.38% 1.26%
wpMemoryUsage 6.41 MB +0% -0% 6.38 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 778056c trunk % Change
mediaProcessingJpeg 402.39 ms +1.11% -0.81% 400.66 ms +0.18% -0.73% 0.43%
mediaProcessingAvif 6119.23 ms +0.48% -0.18% 6132.13 ms +0.48% -0.19% -0.21%
mediaProcessingJpegToAvif 4225.58 ms +0.37% -0.17% 4228.72 ms +0.16% -0.19% -0.07%

media-upload

Metric 778056c trunk % Change
jpegUploadProcessing 1713.09 ms +13.69% -15% 1458.98 ms +0.85% -0.63% 17.42%
pngUploadProcessing 258.63 ms +11.5% -32.65% 176.12 ms +38.87% -3.86% 46.85%
largeJpegUploadProcessing 1942.95 ms +0.45% -24.95% 1705.01 ms +13.55% -13.9% 13.96%
multipleImageUploadProcessing 2005.66 ms +1.91% -0.21% 2045.05 ms +0.2% -1.84% -1.93%

post-editor

Metric 778056c trunk % Change
serverResponse 306.14 ms +4.29% -7.45% 316.55 ms +2.75% -11.29% -3.29%
firstPaint 276.97 ms +36.48% -12.91% 285.07 ms +5.77% -23.56% -2.84%
domContentLoaded 655.04 ms +4.78% -0.74% 664.7 ms +1.57% -1.59% -1.45%
loaded 655.76 ms +4.78% -0.74% 665.44 ms +1.57% -1.59% -1.45%
firstContentfulPaint 386.05 ms +6.49% -0.98% 392.72 ms +2.17% -2.98% -1.7%
firstBlock 1741.09 ms +1.54% -3.11% 1723.9 ms +0.66% -0.69% 1%
type 13.97 ms +1.79% -6.94% 14.18 ms +3.17% -12.83% -1.48%
typeWithoutInspector 14.04 ms +0.5% -9.54% 13.89 ms +3.46% -11.81% 1.08%
typeWithTopToolbar 18.48 ms +1.73% -6.6% 18.66 ms +3.54% -10.02% -0.96%
typeContainer 6.43 ms +2.33% -1.87% 6.56 ms +3.81% -13.87% -1.98%
focus 90.72 ms +2.23% -3.44% 92.68 ms +1% -11.53% -2.11%
firstFocus 199.28 ms +0% -0% 190.31 ms +0% -0% 4.71%
selectAll 304.16 ms +2% -2.13% 297.54 ms +0.46% -2.14% 2.22%
undo 24.44 ms +4.75% -4.75% 25.14 ms +2.98% -8.15% -2.78%
listViewOpen 58.48 ms +18.93% -2.22% 54.79 ms +17.43% -4.47% 6.73%
inserterOpen 34.62 ms +2.66% -13.49% 31.83 ms +0.85% -9.14% 8.77%
inserterHover 8.87 ms +14.88% -4.85% 9.1 ms +3.85% -12.42% -2.53%
inserterSearch 6.77 ms +12.26% -4.14% 6.88 ms +6.4% -5.38% -1.6%
loadPatterns 497.27 ms +3.98% -2.17% 514.23 ms +2.04% -5.36% -3.3%
wpTotal 297.49 ms +4.47% -7.63% 308.07 ms +2.74% -11.62% -3.43%
wpMemoryUsage 14.77 MB +0% -0% 14.74 MB +0% -0% 0.24%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 778056c trunk % Change
serverResponse 255.47 ms +1% -9.24% 243.08 ms +1.16% -10.35% 5.1%
firstPaint 251.84 ms +7.19% -14.05% 230.02 ms +5.47% -11.79% 9.49%
domContentLoaded 566.45 ms +4.82% -1.04% 533.53 ms +5.85% -0.52% 6.17%
loaded 567.16 ms +4.81% -1.05% 534.28 ms +5.93% -0.52% 6.15%
firstContentfulPaint 338.85 ms +2.84% -2.94% 311.52 ms +1.71% -0.6% 8.77%
firstBlock 1687.83 ms +1.07% -1.63% 1609.91 ms +2.7% -2.22% 4.84%
type 12.44 ms +7.15% -6.75% 11.99 ms +5.09% -4.25% 3.75%
navigate 75.89 ms +2.87% -11.99% 78.76 ms +5.83% -3.29% -3.64%
loadPatterns 895.15 ms +6.89% -8.86% 941.21 ms +6.72% -16.89% -4.89%
loadPages 930.23 ms +5.46% -0.76% 922.49 ms +1.01% -1.39% 0.84%
wpTotal 248.97 ms +0.88% -9.58% 236.67 ms +1.31% -10.48% 5.2%
wpMemoryUsage 12.79 MB +0% -0% 12.75 MB +0% -0% 0.27%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

33c2bf0 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.

Page List converts to Navigation Links with entity bindings in /test/e2e/specs/editor/blocks/navigation.spec.js, passed after 1 failed attempt.
Error: expect(locator).toContainText(expected) failed

Locator: getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ })
Expected substring: "test-page-1"
Received string:    "Link to:Cat/catPagePublished"
Timeout: 5000ms

Call log:
  - Expect "toContainText" getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ }) with timeout 5000ms
  - waiting for getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ })
    14 × locator resolved to <button type="button" aria-expanded="false" aria-haspopup="dialog" class="components-button link-preview-button is-next-40px-default-size is-secondary">…</button>
       - unexpected value "Link to:Cat/catPagePublished"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation.spec.js:1949:31
Undo restores the post selection when another synced entity is loaded in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 0,
+   "offset": 0,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
does not select blocks in the canvas preview when editing from the sidebar in /test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator: getByRole('combobox', { name: 'Search or type URL' })
Expected: focused
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeFocused" getByRole('combobox', { name: 'Search or type URL' }) with timeout 5000ms
  - waiting for getByRole('combobox', { name: 'Search or type URL' })

    at LinkControl.useLinkControlSearch (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:416:47)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:179:21
region-scoped focus that refrains on traversals in /test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts, passed after 1 failed attempt.
Error: expect(locator).toHaveCount(expected) failed

Locator:  locator('[data-wp-router-region="lifecycle-a"] :focus')
Expected: 0
Received: 1
Timeout:  5000ms

Call log:
  - Expect "toHaveCount" locator('[data-wp-router-region="lifecycle-a"] :focus') with timeout 5000ms
  - waiting for locator('[data-wp-router-region="lifecycle-a"] :focus')
    14 × locator resolved to 1 element
       - unexpected value "1"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:1652:37

33c2bf0 Run

mirka added 3 commits November 6, 2026 03:50
`ColorPalette` picks a check mark color that contrasts with the swatch,
but forced colors replace the swatch with `Canvas`, so the check mark
could match its background. Also handle disabled pressed buttons in the
widgets header, where plugins can add them, and record why the swatch
reset and the toolbar fill work the way they do.
@mirka mirka added Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta and removed Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Nov 6, 2026
@mirka

mirka commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

It's a close call but I'm leaning towards not backporting this. This has been a long-standing bug, and there is a low-but-non-zero potential for third-party regressions.

@mirka
mirka marked this pull request as ready for review November 6, 2026 05:59
@mirka
mirka requested a review from a team as a code owner November 6, 2026 05:59
@t-hamano t-hamano added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Nov 6, 2026

@ciampo ciampo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 🚀

Is there any easy way to remove style overrides outside of components and ui packages?

Is the only clean way to prepare a new Toolbar component in the ui package and refactor to it?

@mirka

mirka commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Is the only clean way to prepare a new Toolbar component in the ui package and refactor to it?

Well, the todo I added about possibly having a way to opt out of the ::before stuff could be worth looking into.

@mirka
mirka enabled auto-merge (squash) November 9, 2026 14:54
@mirka
mirka merged commit e63ec26 into trunk Nov 9, 2026
81 checks passed
@mirka
mirka deleted the components-forced-colors-pressed-state branch November 9, 2026 15:12
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components [Package] Edit Widgets /packages/edit-widgets [Package] Editor /packages/editor [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