Repository navigation
Twenty Nineteen: Fix console error when tapping a # menu link without a submenu - #15334
HrithikDalal wants to merge 1 commit into
Conversation
… without a submenu. On touch screens, tapping a top-level menu item with a `#` URL checks whether the next sibling is the submenu toggle. Items without children have no next sibling, so this threw a TypeError. Use `nextElementSibling` and check it exists before calling `matches()`. Follow-up to [55970]. See #45903.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the touch-navigation guard and accompanying script-version update.
No open issues 🎉
What changed in this PR
This PR fixes Twenty Nineteen’s touch-navigation error when tapping a # menu link without a submenu, while preserving submenu opening for links with children.
Changes:
- Uses
nextElementSiblingand checks that it exists before callingmatches(). - Bumps the touch-navigation script version to refresh cached copies.
| File | Description |
|---|---|
src/wp-content/themes/twentynineteen/js/touch-keyboard-navigation.js |
Guards the submenu check against a missing sibling element. |
src/wp-content/themes/twentynineteen/functions.php |
Updates the script version for cache invalidation. |
Review effort: Balanced
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
On touch screens, tapping a primary menu item with a
#URL throwsTypeError: Cannot read properties of null (reading 'matches')if the item has no submenu. The touchstart handler callsevent.target.nextSibling.matches(), and for those items there is no next sibling.This switches to
nextElementSiblingand checks it exists first.#items that do have a submenu still open it on tap. The other error in the ticket (event.target.matches is not a functionon focus) was fixed in [55970].Also bumps the script version.
Testing
#that has no child items.#item with children still opens its submenu.Trac ticket: https://core.trac.wordpress.org/ticket/45903
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Co-authoring the fix. Reviewed and tested by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.