Skip to content

Dropdown: Enable initial focus by user input device - #85531

Draft
stokesman wants to merge 3 commits into
trunkfrom
update/dropdown-focus-on-mount-per-input-device
Draft

stokesman wants to merge 3 commits into
trunkfrom
update/dropdown-focus-on-mount-per-input-device

Conversation

@stokesman

@stokesman stokesman commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What?

As a means, this extends the hook useFocusOnMount and Dropdown to facilitate the proper focus behavior by interaction type when opening Dropdown based components. As an end, this makes DropdownMenu focus its popover element when opening with a pointer device whereas keyboard and virtual activation focus the first tabbable element within its popover.

Why?

As an alternative to #85486. In the current state this is not a complete alternative since it lacks the feature where "arrow keys can enter a pointer-opened menu" and some test updates.

How?

  • Extends useFocusOnMount to accept a callback for dynamically determining focus behavior.
  • Alters the onToggle property passed to Dropdown render props so that it accepts an event that's used to detect the appropriate focus behavior.
  • Makes DropdownMenu pass the events used for invoking onToggle through it.

Testing Instructions

These are pulled from #85486 and represent what this should do to be a complete alternative which it is not yet.

  1. Open DropdownMenu Default with a pointer. The menu should have focus without focusing its first item.
  2. Press ArrowDown to enter the first item, or reopen and press ArrowUp to enter the last. Escape should close the menu and restore trigger focus.
  3. Repeat in the editor's List View block settings menu and the classic Site Editor's Add Pattern menu.
  4. Check explicit popoverProps.focusOnMount settings and consumer focus handlers. A later controlled opening should use the default first-item focus.

Testing Instructions for Keyboard

  1. Tab to a DropdownMenu trigger. Enter, Space, and ArrowDown should open and focus the first item.
  2. Navigate and select an item, then reopen and dismiss with Escape. Focus should return to the trigger.
  3. Focus the root of a TabbableContainer cycle={false}. Shift+Tab should leave it; Tab should enter its first tab stop.

Screenshots or screencast

Before After

Use of AI Tools

None so far.

@stokesman stokesman added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Oct 26, 2026
@github-actions github-actions Bot added the [Package] Compose /packages/compose label Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

📦 Bundle size

Size Change: +159 B (0%)

Total Size: 9.07 MB

📦 View Changed
Filename Size Change
build/scripts/components/index.min.js 372 kB +106 B (+0.03%)
build/scripts/compose/index.min.js 11.8 kB +53 B (+0.45%)

607f410 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 236ce1e trunk % Change
timeToFirstByte 53.9 ms +13.45% -2.23% 54.05 ms +13.14% -3.24% -0.28%
largestContentfulPaint 92 ms +13.04% -4.35% 88 ms +11.36% -0% 4.55%
lcpMinusTtfb 35.8 ms +14.53% -4.75% 34.6 ms +14.88% -4.62% 3.47%
wpBeforeTemplate 29.16 ms +14.99% -1.17% 28.57 ms +14.95% -0.88% 2.07%
wpTemplate 20.93 ms +7.6% -4.06% 20.97 ms +5.05% -4.01% -0.19%
wpTotal 50.21 ms +12.45% -2.57% 50.59 ms +11.8% -3.87% -0.75%
wpMemoryUsage 7.68 MB +0% -0% 7.65 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 236ce1e trunk % Change
timeToFirstByte 46 ms +9.78% -1.96% 45.75 ms +5.03% -1.09% 0.55%
largestContentfulPaint 100 ms +6% -0% 100 ms +2% -0% 0%
lcpMinusTtfb 55.05 ms +0.45% -1.18% 54.4 ms +0.74% -2.11% 1.19%
wpBeforeTemplate 26.94 ms +2.97% -2.08% 26.5 ms +3.51% -1.21% 1.66%
wpTemplate 16.27 ms +4.61% -2.58% 16.05 ms +3.24% -0.69% 1.37%
wpTotal 43.1 ms +8.47% -1.88% 42.62 ms +5.84% -1.06% 1.13%
wpMemoryUsage 6.37 MB +0% -0% 6.34 MB +0% -0% 0.54%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 236ce1e trunk % Change
mediaProcessingJpeg 397.73 ms +0.82% -0.82% 401.16 ms +0.4% -1.35% -0.86%
mediaProcessingAvif 6083.13 ms +0.06% -0.22% 6125.66 ms +0.37% -0.08% -0.69%
mediaProcessingJpegToAvif 4197.39 ms +0.17% -0.18% 4252.43 ms +0.07% -0.23% -1.29%

media-upload

Metric 236ce1e trunk % Change
jpegUploadProcessing 1448.53 ms +34.31% -1.21% 1421.4 ms +1.88% -0.49% 1.91%
pngUploadProcessing 204.86 ms +7.87% -15.08% 191.5 ms +21.24% -8.71% 6.98%
largeJpegUploadProcessing 1413 ms +0.77% -0.15% 1416.59 ms +1.38% -0.75% -0.25%
multipleImageUploadProcessing 1588.08 ms +32.41% -1.5% 2054.15 ms +1.71% -1.68% -22.69%

post-editor

Metric 236ce1e trunk % Change
serverResponse 497.39 ms +2.44% -4.42% 489.15 ms +6.43% -5.96% 1.68%
firstPaint 449.64 ms +14.62% -39.67% 423.64 ms +17.83% -19.05% 6.14%
domContentLoaded 1191.94 ms +3.84% -3.5% 1182.89 ms +2.14% -1.32% 0.77%
loaded 1193.19 ms +3.81% -3.52% 1184.03 ms +2.14% -1.31% 0.77%
firstContentfulPaint 513.52 ms +3.14% -6.79% 492.05 ms +7% -22.44% 4.36%
firstBlock 3353.34 ms +1.51% -0.82% 3337.9 ms +3.53% -0.74% 0.46%
type 16.59 ms +6.81% -2.29% 16.63 ms +4.39% -2.77% -0.24%
typeWithoutInspector 16.27 ms +9.65% -1.48% 16.81 ms +7.61% -1.07% -3.21%
typeWithTopToolbar 21.61 ms +5.6% -3.89% 21.48 ms +2.61% -2.37% 0.61%
typeContainer 7.64 ms +12.3% -5.89% 7.95 ms +11.7% -6.04% -3.9%
focus 114.37 ms +7.43% -2.13% 117.99 ms +3.3% -10.93% -3.07%
firstFocus 221.6 ms +0% -0% 234.92 ms +0% -0% -5.67%
selectAll 522.14 ms +5.68% -1.66% 549.92 ms +2.22% -0.96% -5.05%
listViewOpen 82.52 ms +10.62% -12.22% 82.36 ms +3.39% -9.71% 0.19%
inserterOpen 42.27 ms +4.35% -9.65% 40.59 ms +4.58% -3.6% 4.14%
inserterHover 10.49 ms +7.53% -5.72% 11.52 ms +10.07% -4.86% -8.94%
inserterSearch 8.07 ms +4.58% -9.54% 8.31 ms +2.65% -9.63% -2.89%
loadPatterns 624.3 ms +1.99% -1.14% 611.86 ms +3.16% -2.27% 2.03%
wpTotal 488.1 ms +1.98% -4.57% 479.42 ms +6.57% -5.94% 1.81%
wpMemoryUsage 14.71 MB +0% -0% 14.68 MB +0% -0% 0.24%
wpDbQueries 55 +0% -1.82% 55 +0% -1.82% 0%

site-editor

Metric 236ce1e trunk % Change
serverResponse 515.08 ms +4.7% -8.68% 481.72 ms +6.03% -1.99% 6.93%
firstPaint 252.91 ms +34.77% -7.07% 274.79 ms +10.78% -15.25% -7.96%
domContentLoaded 1257.38 ms +3.39% -3.05% 1276.92 ms +2.16% -1.1% -1.53%
loaded 1258.51 ms +3.4% -3.05% 1278.05 ms +2.15% -1.07% -1.53%
firstContentfulPaint 474.64 ms +8.09% -25.33% 522.17 ms +2.47% -21.59% -9.1%
firstBlock 4535.17 ms +1.02% -1.15% 4627.56 ms +0.25% -0.67% -2%
type 17.72 ms +2.31% -2.31% 18.6 ms +7.26% -4.57% -4.73%
navigate 122.95 ms +6.98% -11.91% 116.28 ms +12.68% -3.73% 5.74%
loadPatterns 1305.09 ms +5.99% -3.8% 1294.73 ms +8.72% -4.97% 0.8%
loadPages 1005.25 ms +2.23% -2.29% 999.13 ms +3.87% -4.74% 0.61%
wpTotal 505.76 ms +4.72% -8.88% 472.36 ms +6.08% -1.96% 7.07%
wpMemoryUsage 12.73 MB +0% -0% 12.70 MB +0% -0% 0.24%
wpDbQueries 44 +2.27% -0% 44 +2.27% -0% 0%

607f410 Run

@ciampo

ciampo commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

#85486 merged, feel free to iterate and refine this approach. Happy to review it when ready

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Package] Compose /packages/compose [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants