Menu: Return focus to the trigger button after closing a Modal opened from menu item - #80735
Menu: Return focus to the trigger button after closing a Modal opened from menu item#80735yashjawale wants to merge 11 commits into
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. |
|
Is it possible to add regression test coverage for this? Something in |
|
Updated to include a test case for checking focused element after modal is closed when opened from menu. Checked by running the case on trunk & current branch. On trunk: On current branch: With the test I noticed another thing, since the I've moved them outside so Ariakit detects non-zero duration regardless of motion preference, which delays the unmounting of popover in time, so For users with reduced motion, there still isn't any visual animation for this component nor do they see the popover showing up longer than it did before. |
That's great that you were able to find an additional issue through the tests! 🎉 I'll be review this one shortly. |
|
One thing I'd worry about is that this seems to effectively undo what @ciampo described as an intentional decision in #77460 , which may bring its own separate issues?
(emphasis mine for the change that's being undone here) |
|
It'd be good to understand what the practical difference would be between this and just reverting #77460. @ciampo has limited availability until next week but it'd be good to get his feedback, or also @mirka as a reviewer of #77460. Functionally, this seems fine, and I confirmed that it does fix the bug. The added regression coverage will be nice to have. But since it seems like this largely backtracks what #77460 was aimed at implementing, I'd like to better understand how these two pull requests interact. If I had to choose between functioning focus return and a brief delay in scroll-lock clean-up (if that's the actual issue, unclear), then I'd opt for the focus return for WordPress 7.1. |
|
I confirm that this PR essentially un-does #77460 , which was a deliberate fix. It would be interesting to understand if we can achieve a similar fix to that of #77460 without its drawback. I don't have much time on my hands, but we may want to look at the Ariakit update PR, too, in the chance that it allows un-doing #77460 without re-introducing the regression. Alternatively, we could add some imperative code in Menu to handle the focus return manually (potentially focus |
|
Thanks! Got to learn a lot while digging into this... I checked out to commit 0f0ca8f which was before #77460 was merged. And can confirm that the focus bug doesn't appear there. However, it returns back when using reduced motion settings. I think we'll still need the change of moving Will continue to check out other approaches & I'll post an update as soon as I find something. |
|
Updated with alternative approach of handling focus return manually. |
|
I'm still not convinced about this approach, which would cause a new regression when returning focus on non-modal popovers. I'm proposing an alternative approach in #81164, I'll soon mark it as ready for review |
What?
Closes #80734
This PR fixes focus issue after closing any popovers that appear from triggers in menu.
Why?
This PR restructures the Menu popover so Ariakit renders
MenuMotionRootdirectly, making it aware of the CSS transition duration and fixing focus restoration timing.How?
In
popover.tsxSpread Ariakit's htmlProps (except children) ontoMenuMotionRootinstead ofMenuSurfaceand then place children insideMenuSurfaceexplicitly.In
style.ts, changeMenuMotionRootselectors from:has(> MenuSurface[data-enter])to&[data-enter]etc., sincedata-*attributes now live onMenuMotionRoot.Testing Instructions
control+option+ Left/Right arrows & Space for selecting the options)Screenshots or screencast
Screen.Recording.2026-07-27.at.5.29.04.PM.mov
Use of AI Tools
Assisted by DeepSeek V4 Flash via Opencode
All changes reviewed & tested manually.