Navigation Block: Focus trap behavior changes after submenu toggle
Description
After toggling a navigation submenu open and closed using keyboard (Space/Enter), the Shift+Tab behavior changes unexpectedly. Focus trapping behaves differently before and after interaction, even though the submenu returns to its closed state.
Step-by-step reproduction instructions
- Navigate to a page with a Navigation block containing a submenu (dropdown)
- Set screen width to small width to activate mobile menu.
- Tab to the submenu toggle button
- Before interaction: Press Shift+Tab — focus moves naturally backward through the navigation items
- Press Space/Enter to open the submenu
- Press Space/Enter again to close the submenu (returns to
aria-expanded="false") - After interaction: Press Shift+Tab — focus now jumps unexpectedly to the tab item that's after the menu toggle button.
Screenshots, screen recording, code snippet
No response
Environment info
WP 6.9.0
Please confirm that you have searched existing issues in the repo.
- [x] Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- [x] Yes
Please confirm which theme type you used for testing.
- [x] Block
- [ ] Classic
- [ ] Hybrid (e.g. classic with theme.json)
- [ ] Not sure
Reproduction Report
Description
This report verifies whether the issue “Focus trap behavior changes after submenu toggle” can be reproduced.
Environment
- WordPress: 6.9.4
- PHP: 8.2.27
- Server: nginx/1.26.1
- Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.2.27)
- Browser: Chrome 146.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.4
- MU Plugins: None activated
- Plugins:
- Gutenberg 22.8.2
- Test Reports 1.2.1
Steps Performed
- Opened a page containing a Navigation block with multiple items, including one with a submenu
- Switched to a small viewport width to trigger the mobile menu layout (also tested on desktop)
- Navigated using
Tabuntil reaching:- the navigation menu toggle (mobile), or
- the submenu toggle (desktop)
- Verified that before interaction,
Shift + Tabcorrectly moved focus backward - Opened and then closed:
- the mobile navigation overlay, or
- the submenu dropdown (desktop)
- Tested
Shift + Tabagain after interaction
Actual Results
- ❌ The reported issue could not be reproduced
- Focus behaviour remained consistent before and after submenu interaction
Shift + Tabcontinued to move focus backward as expected
Additional Notes
- Hey @earthlingdavey, thanks for the report! I assume there may be a mismatch with the default Navigation block behavior, where in mobile view (e.g. with Twenty Twenty-Five), submenus are typically expanded within the overlay rather than using a separate toggle.
- I tested in both mobile (overlay) and desktop (dropdown) contexts with various keyboard navigation patterns before and after interaction, but could not reproduce any unexpected focus behavior.
Shift + Tabworked as expected in all cases. - It could be possible this is theme-specific or depends on a customized Navigation block implementation. If I may have missed any crucial step, could you please share a screen recording or more detailed steps along with the theme you’re using? I’ll be happy to test it again.
Supplemental Artifacts
Mobile Layout
https://github.com/user-attachments/assets/f8c5f4c7-8845-465e-9deb-c0a3a6c569c2
Desktop Layout
https://github.com/user-attachments/assets/603c1e34-c560-45a6-a6dd-4105ec96f9a0
Hi, This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps. Thanks for helping out.
Closing as non reproducible. Correct me if I'm wrong.