Skip to content

UI: Add high contrast variants to Menu and Popover - #83850

Closed
ciampo wants to merge 5 commits into
trunkfrom
codex/ui-popup-high-contrast
Closed

ciampo wants to merge 5 commits into
trunkfrom
codex/ui-popup-high-contrast

Conversation

@ciampo

@ciampo ciampo commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to the high contrast variant discussion in #82966.

What?

Add variant="high-contrast" to Menu.Popup and Popover.Popup.

Why?

Block toolbar popups need a stronger boundary than the default popup styling. A shared visual variant makes that appearance available without repeating custom styles in each consumer.

How?

Use a token-based dark border, small corner radius, and no shadow. Share the styling between both components. Menu separators and the Popover arrow match the popup border. Each popup opts in explicitly, including submenu popups. Existing default and unstyled appearances stay the same.

This PR adds the component support and Storybook examples. Adoption in toolbar consumers can follow separately.

Testing Instructions

  1. Run npm run storybook:dev and open Menu → High Contrast under @wordpress/ui.
  2. Open the menu and its Move to submenu. Both popups should have a dark border, small corners, and no shadow. Menu separators should match the border color.
  3. Open Popover → High Contrast. Its arrow should match the popup border.
  4. Compare the Default stories and Popover's Unstyled story. Check both high contrast stories with WordPress global CSS enabled and disabled.

Testing Instructions for Keyboard

Open the Menu with Enter, navigate to Move to with arrow keys, and open the submenu with Right Arrow. Escape should close the menus and return focus to the trigger. Open the Popover with Enter. Escape should close it and return focus to its trigger.

Screenshot

Screenshot 2026-09-30 at 11 09 59

Follow-up

Note

If the theme gains a high contrast setting, consumers could wrap an individual Menu or Popover in a high contrast theme provider. That could make this variant prop unnecessary and provide a better long-term approach. We are not ready to implement that theme-wide setting yet.

Use of AI Tools

Implemented and verified with OpenAI Codex.

@github-actions github-actions Bot added the [Package] UI /packages/ui label Sep 30, 2026
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 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: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>

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

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

📦 Bundle size

Size Change: +953 B (+0.01%)

Total Size: 8.25 MB

📦 View Changed
Filename Size Change
build/modules/block-library/playlist/view.min.js 18.5 kB +31 B (+0.17%)
build/scripts/block-editor/index.min.js 516 kB +305 B (+0.06%)
build/scripts/block-library/index.min.js 366 kB +23 B (+0.01%)
build/scripts/components/index.min.js 333 kB +165 B (+0.05%)
build/scripts/edit-site/index.min.js 382 kB +98 B (+0.03%)
build/scripts/editor/index.min.js 616 kB +209 B (+0.03%)
build/scripts/media-utils/index.min.js 206 kB +122 B (+0.06%)

7458480 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 4f11c49 trunk % Change
timeToFirstByte 56.85 ms +11.7% -1.5% 57 ms +10.7% -2.02% -0.26%
largestContentfulPaint 100 ms +4% -8% 98 ms +2.04% -6.12% 2.04%
lcpMinusTtfb 36.85 ms +23.07% -3.12% 34.55 ms +25.62% -4.78% 6.66%
wpBeforeTemplate 28.22 ms +14.64% -1.95% 28.39 ms +14.58% -1.2% -0.6%
wpTemplate 24.68 ms +4.86% -2.59% 24.79 ms +3.79% -3.87% -0.44%
wpTotal 53.15 ms +11.76% -1.47% 53.3 ms +11.18% -2.08% -0.28%
wpMemoryUsage 7.62 MB +0% -0% 7.59 MB +0% -0% 0.46%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric 4f11c49 trunk % Change
timeToFirstByte 43.25 ms +9.36% -2.31% 42.65 ms +5.51% -0.94% 1.41%
largestContentfulPaint 92 ms +4.35% -0% 92 ms +4.35% -2.17% 0%
lcpMinusTtfb 49.2 ms +1.52% -1.32% 49.15 ms +1.02% -5.29% 0.1%
wpBeforeTemplate 26.74 ms +8.26% -2.69% 26.09 ms +3.3% -0.73% 2.49%
wpTemplate 13.68 ms +5.63% -1.46% 13.65 ms +2.86% -0.81% 0.22%
wpTotal 40.49 ms +9.34% -2.57% 39.94 ms +5.86% -1.13% 1.38%
wpMemoryUsage 6.11 MB +0% -0% 6.07 MB +0% -0% 0.59%
wpDbQueries 10 +0% -0% 10 +0% -0% 0%

media-processing

Metric 4f11c49 trunk % Change
mediaProcessingJpeg 402.04 ms +2.52% -1.04% 396.16 ms +0.95% -0.46% 1.48%
mediaProcessingAvif 6046.53 ms +0.29% -0.16% 6052.41 ms +0.1% -0.17% -0.1%
mediaProcessingJpegToAvif 4178.91 ms +0.09% -0.23% 4172.72 ms +0.2% -0.11% 0.15%

media-upload

Metric 4f11c49 trunk % Change
jpegUploadProcessing 1452.52 ms +34.98% -1.97% 1418.33 ms +0.69% -0.77% 2.41%
pngUploadProcessing 191.07 ms +32.83% -9.11% 183.48 ms +17.71% -4.23% 4.14%
largeJpegUploadProcessing 1421.28 ms +1.53% -1.37% 1413.98 ms +0.29% -1.02% 0.52%
multipleImageUploadProcessing 1606.99 ms +31.41% -2.01% 1558.55 ms +37.44% -0.34% 3.11%

post-editor

Metric 4f11c49 trunk % Change
serverResponse 494.86 ms +3.95% -4.96% 509.4 ms +5.33% -5.23% -2.85%
firstPaint 231.16 ms +4.73% -13.44% 230.26 ms +41.14% -4.27% 0.39%
domContentLoaded 1094.47 ms +1.63% -0.88% 1087.91 ms +1.35% -0.52% 0.6%
loaded 1095.81 ms +1.63% -0.87% 1089.32 ms +1.32% -0.52% 0.6%
firstContentfulPaint 454.95 ms +1.39% -3.64% 451.95 ms +2.3% -3.3% 0.66%
firstBlock 3306.27 ms +0.08% -0.87% 3269.42 ms +1.28% -0.27% 1.13%
type 18.2 ms +7.69% -7.03% 18.38 ms +5.5% -3.86% -0.98%
typeWithoutInspector 17.76 ms +11.49% -0.9% 17.43 ms +5.39% -9.93% 1.89%
typeWithTopToolbar 24.31 ms +28.59% -13.82% 22.22 ms +4.64% -3.2% 9.41%
typeContainer 1.21 ms +23.97% -41.32% 1.36 ms +11.76% -40.44% -11.03%
focus 12.63 ms +28.98% -11.72% 12.96 ms +9.34% -9.34% -2.55%
firstFocus 47.05 ms +0% -0% 28.67 ms +0% -0% 64.11%
selectAll 1527.08 ms +1.72% -2.09% 1527.3 ms +1.86% -2.65% -0.01%
listViewOpen 63.78 ms +3.83% -8.15% 62.07 ms +4.53% -4.78% 2.75%
inserterOpen 24.27 ms +7.33% -9.06% 22.09 ms +12.68% -4.21% 9.87%
inserterHover 2.32 ms +3.45% -12.07% 2.15 ms +8.84% -16.74% 7.91%
inserterSearch 7.82 ms +5.75% -8.18% 7.83 ms +1.79% -3.07% -0.13%
loadPatterns 624.28 ms +1.85% -2.02% 623.08 ms +3.98% -1.15% 0.19%
wpTotal 484.98 ms +4.11% -5% 499.35 ms +5.41% -5.21% -2.88%
wpMemoryUsage 13.16 MB +0% -0% 13.13 MB +0% -0% 0.25%
wpDbQueries 54 +0% -0% 54 +0% -1.85% 0%

site-editor

Metric 4f11c49 trunk % Change
serverResponse 481.4 ms +4.53% -1.54% 531 ms +0.59% -3.49% -9.34%
firstPaint 248.45 ms +7.54% -17.86% 254.02 ms +26.27% -6.53% -2.19%
domContentLoaded 1131.99 ms +1.24% -0.94% 1182.76 ms +2.99% -0.43% -4.29%
loaded 1133.07 ms +1.25% -0.93% 1184.03 ms +3.02% -0.42% -4.3%
firstContentfulPaint 444.33 ms +2.98% -0.77% 476.19 ms +1.05% -1.55% -6.69%
firstBlock 4138.04 ms +0.18% -0.58% 4401.95 ms +3.25% -1.04% -6%
type 17.48 ms +3.03% -11.33% 18.87 ms +2.65% -2.65% -7.37%
navigate 112.14 ms +4.34% -6.92% 120.11 ms +11.31% -6.68% -6.64%
loadPatterns 1239.18 ms +10.54% -0.83% 1397.58 ms +12.61% -2.02% -11.33%
loadPages 1074.25 ms +2.56% -2% 1101.31 ms +4.8% -1.02% -2.46%
wpTotal 471.54 ms +4.74% -1.57% 520.91 ms +0.59% -3.47% -9.48%
wpMemoryUsage 12.14 MB +0% -0% 12.11 MB +0% -0% 0.3%
wpDbQueries 43 +2.33% -0% 43.5 +1.15% -1.15% -1.15%

7458480 Run

@ciampo ciampo added the [Type] Enhancement A suggestion for improvement. label Sep 30, 2026
@ciampo ciampo self-assigned this Sep 30, 2026
@ciampo
ciampo requested a review from a team September 30, 2026 09:11
@ciampo
ciampo marked this pull request as ready for review September 30, 2026 09:11
@ciampo
ciampo requested a review from a team as a code owner September 30, 2026 09:11
@ciampo
ciampo requested a review from Mamaduka September 30, 2026 09:12
@jameskoster

Copy link
Copy Markdown
Contributor

I'm a little bit anxious about adding a variant just to support one unique piece of UI (toolbar). What's to stop consumers misusing?

Would it be better to wrap toolbars in a ThemeProvider that increases the contrast of all children? I say this with the recognition that the color scales are not configurable based on contrast yet :)

@ciampo

ciampo commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Would it be better to wrap toolbars in a ThemeProvider that increases the contrast of all children? I say this with the recognition that the color scales are not configurable based on contrast yet :)

It would be, but that's a much bigger task. I mentioned it in the PR description that in the future we should indeed use a high-contrast setting on ThemeProvider — but for the sake of enabling Menu usage in the toolbar, I thought this would be a worthy compromise that we can later remove.

@jameskoster

Copy link
Copy Markdown
Contributor

Of course you did, sorry I totally skipped that notice. I guess if we're happy to deprecate in the future this seems fine.

Comment on lines +222 to +225
/**
* Set `variant="high-contrast"` on each popup, including submenu popups, to use
* a strong border and separators, small radius, and no shadow.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given the misuse risk, can we add stronger guidance on when exactly this variant should be used?

And regarding the risk of the design changing in the future, it might be useful to know whether this variant is only relevant to first-party development, or if there are instances where third-parties need to use it.

Based on how narrow we can make the usage guidance, we could perhaps even choose a better name for the variant. So if the design spec changes in the future, we could just change the design of the variant while also deprecating it. high-contrast makes that impossible. I know the name was chosen to be less prescriptive, but given the misuse and design change concerns, it might actually be better to be more prescriptive.

Just some thoughts.

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.

If we make the variant inherit (and/or even move it from the popup to the root), then I assume that third party consumers wouldn't really need to set it.

Re. the name, we could move back to toolbar, and otherwise the other name that came to mind was strong 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I still don't think it's appropriate to test styles like this 😅

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 would ideally be a snapshot (ie viz reg) test, but we don't have the infra for it.

Would you rather remove the test entirely? Happy to do that

@jasmussen

Copy link
Copy Markdown
Contributor

Could be my eyes, but the corner radius looks wrong. It's tricky, 2px isn't 2px if the stroke is on the outside, then it's 1px. Not saying we should move the stroke on the inside, just that the math is dependant on whether the stroke is inner or outer. If it's outer, the radius should be [radius + border-width].

@ciampo

ciampo commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

I'm also echoing @t-hamano 's point about #83850 being an implicit dependency to this PR.

I'd be personally in favaour of dropping the "high contrast" look altogeher from the toolbar, which would then implicitly make this "high contrast" variant not needed. It feels like a cleaner direction, more aligned with the DS visual language.

@ciampo

ciampo commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Closing this PR as I'm hoping that we can end up following the following approach:

  1. refactor toolbar to use lighter borders/strokes, matching existing Menu;
  2. if the "strong" look is non-negotiable, introduce theme-wide high-contrast mode, wrap Toolbar its descendat menus in it.

Solution no. 2 would retain the current look in a DS-compliant way, although it would take longer to get there

@ciampo ciampo closed this Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] UI /packages/ui [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants