Skip to content

Twenty Twelve: Fix sub-menu access on touch devices - #14983

Open
Sukhendu2002 wants to merge 1 commit into
WordPress:trunkfrom
Sukhendu2002:30686-twentytwelve-touch-submenu
Open

Sukhendu2002 wants to merge 1 commit into
WordPress:trunkfrom
Sukhendu2002:30686-twentytwelve-touch-submenu

Conversation

@Sukhendu2002

@Sukhendu2002 Sukhendu2002 commented Oct 27, 2026 •

Copy link
Copy Markdown

The touch handler in Twenty Twelve's navigation.js is delegated from body since [30746] (https://core.trac.wordpress.org/ticket/24767). That change moved it off the links so it would also match .page_item_has_children. Since Chrome 56 and iOS Safari 11.3, touchstart listeners on window, document and body are passive by default, so the handler's e.preventDefault() is ignored. Chrome logs:

Unable to preventDefault inside passive event listener due to target being treated as passive.

As a result, on touch devices the first tap on a parent menu item follows its link, and the sub-menu can never be reached.

Changes

  • Delegate the touchstart handler from .main-navigation instead of body. This keeps the selectors from [30746]. A listener on a non-document-level element is not passive, so preventDefault() takes effect again.
  • Only intercept the tap when (min-width: 600px) matches. That is the breakpoint where style.css hides sub-menus behind hover. Below it, the toggle menu already shows sub-menus inline, so a parent link should still work on the first tap.
  • Bump the twentytwelve-navigation script version to bust caches.

Twenty Thirteen's handler binds directly to the links and still works, so no change is needed there. Twenty Fourteen is tracked separately in https://core.trac.wordpress.org/ticket/30575.

Testing instructions

  1. Activate Twenty Twelve.
  2. Create a menu with a parent item and one child item, and assign it to the Primary location.
  3. Open the site on a tablet, or in browser dev tools with touch emulation, at a width of 600px or more.
  4. Tap the parent item.
    • Before: the browser navigates to the parent link.
    • After: the sub-menu opens and the page doesn't change.
  5. Tap the child item. It navigates to the child link.
  6. Reload, then tap the parent item twice. The second tap navigates to the parent link.
  7. Below 600px, open the menu toggle and tap the parent item. It navigates on the first tap, as it does on trunk.
  8. Remove the menu from the Primary location, so pages with child pages are listed instead (the .page_item_has_children fallback), and repeat steps 4–6.
  9. With a mouse and keyboard, Tab through the menu. Sub-menus still open on focus.

Trac ticket: https://core.trac.wordpress.org/ticket/30686

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigating the root cause, initial patch drafting.


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.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@Sukhendu2002
Sukhendu2002 marked this pull request as ready for review October 27, 2026 09:57
@github-actions

Copy link
Copy Markdown

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:

Props sukhendu2002.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant