Make WordPress Core

Opened 12 years ago

Last modified 3 weeks ago

#30686 assigned defect (bug)

Twenty Fourteen/Thirteen/Twelve Navbar submenu behaviour

Reported by: trenzterra Owned by:
Priority: normal Milestone: Future Release
Component: Bundled Theme Version: 4.0.1
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

As you all may know, both 2014/13/12 themes require you to hover over a menu item in order to access the submenu item. This isn't a problem for desktops but for touchscreen devices this may pose a problem.

I notice this problem has largely been addressed at least for the 2013 and 2012 themes for Android, iOS and Windows Phone devices (see https://core.trac.wordpress.org/ticket/24767#comment:35). However, on my Windows 8 tablet, it still registers the first tap as a click on both Internet Explorer 11 and Mozilla Firefox (Google Chrome works fine). I believe both browsers somehow do not declare whether the device is a touchscreen.

In addition, for the 2014 theme, the (partial) fix isn't even implemented (I don't know how it got implemented for both 2013 and 2012 themes but was overlooked for 2014), therefore you will still find it hard to click on sub-menus if you're using an Android device.

As for the 2013 and 2012 themes, I know that the Windows 8 tablet userbase is comparatively small, but I believe it will grow over the years. I'm not sure how this can be fixed in the mean time (since the hover/click behaviour seems to rely on a touchscreen detection), but I would like to suggest the following:

  • In the Twenty Fifteen theme, this issue seems to be fixed once and for all, as the dropbox arrow next to the menu item is a separate link. Clicking on the arrow itself will maximise/minimise the sub-menu, instead of linking you to the menu item itself.
  • However, the Twenty Fifteen theme's menu is only available at the side, instead of the top.
  • Thus, if the improvements made in the Twenty Fifteen theme could be backported to Fourteen, Thirteen and Twelve. It would be great!

P.S. I'm not sure what to classify this ticket under, but I guess I will leave it as a 'bug' since the hover and click issues have not been completely addressed, especially on the Twenty Fourteen theme. The same behaviour occurs on WordPress 4.0.1 and 4.1 RC.

Change History (16)

#1 @SergeyBiryukov
12 years ago

  • Component General → Bundled Theme

#2 @lancewillett
12 years ago

  • Keywords early needs-patch added
  • Milestone Awaiting Review → Future Release

Thank you trenzterra for this ticket, we'll address this for the 4.2 release early next year.

This ticket was mentioned in ​Slack in #core-themes by lancewillett. ​View the logs.


12 years ago

#4 @trenzterra
12 years ago

Hi,

I think the key in fixing this would be using pointerevents instead of touchevents: ​http://blogs.msdn.com/b/ie/archive/2014/07/31/the-mobile-web-should-just-work-for-everyone.aspx

I thought of this once again after my bug was mentioned for #31762 and I saw ontouchevent being utilised. Ontouchevent isn't supported by IE, and perhaps Firefox for desktop.

I was wondering if this issue is still being considered for 4.2? I wish I could help more but I have little javascript knowledge at best.

Thank you.

Edit: I did more research and touchevents is currently only supported on Chrome for desktop devices. Firefox added it for a while and removed it later due to some scrolling issues, while ie10/11 does not support touch events too on the desktop. Thus, as an interim measure, perhaps you could change the drop down arrow to show the submenu instead of linking it together with the menu link. This is how it currently works on the twenty fifteen theme. In addition, code in pointerevents if you want because Chrome and Firefox are working on implementing this feature in future and it would probably supersede the touchevents standard eventually. With the number of touchscreen laptops growing, I think implementing this would be very useful.

Last edited 12 years ago by trenzterra (previous) (diff)

#5 @lancewillett
12 years ago

I think we'll need to move this to 4.3. If someone can start work on a patch, it'd be helpful to get it moving soon into the next release.

#6 @karmatosed
11 years ago

  • Keywords early removed

#7 @karmatosed
11 years ago

  • Owner set to davidakennedy
  • Status new → assigned

#8 @davidakennedy
10 years ago

There's some work happening in #30575 to improve this in Twenty Fourteen. Once finished, it could probably be ported to at least Twenty Thirteen and maybe Twenty Twelve.

#9 @desrosj
6 years ago

  • Milestone → Awaiting Review

Looks like #30575 is still waiting for a patch refresh.

#10 @karmatosed
3 years ago

  • Owner davidakennedy removed

I am going to unassign you @davidakennedy from this for now as this ticket has been not interacted with for a few years. That said, if you want to take ownership again please reassign.

Looking at this ticket the next recommendation I would give would be to test and confirm this is still an issue and if so look to address in a patch.

Last edited 3 years ago by karmatosed (previous) (diff)

#11 @karmatosed
3 years ago

  • Milestone Awaiting Review → Future Release

#12 @karmatosed
8 weeks ago

  • Keywords needs-refresh added; needs-patch removed

#13 @sukhendu2002
6 weeks ago

I tested this against current trunk. The issue is still reproducible:

  • Chrome: the first tap follows the parent link in Twenty Twelve and Twenty Thirteen.
  • WebKit: the first tap follows the parent link in Twenty Twelve and Twenty Fourteen.

Twenty Twelve and Twenty Thirteen still rely on 'ontouchstart' in window, which is not reliable capability detection. Twenty Fourteen has no equivalent touch handling and depends on browser-specific synthetic hover behavior.

Rather than replacing this with another touch/pointer heuristic, I recommend following Twenty Fifteen’s established approach: add a separate, accessible submenu disclosure button while leaving the parent link responsible only for navigation.

Before preparing a patch, it would be helpful to confirm with the Bundled Themes and Accessibility maintainers whether this behaviour should be backported to all three themes.

#14 @karmatosed
3 weeks ago

Revisiting this much of the original report concerns IE11 and Windows 8 - which is no longer supported. However, the latest testing seems to change this to say that it now can be replicated in trunk on supported browsers.

If we confirm that is case, then a patch refresh (for today) needs making and yes rolling out.

This ticket was mentioned in ​PR #14983 on ​WordPress/wordpress-develop by ​@sukhendu2002.


3 weeks ago
#15

  • Keywords has-patch added; needs-refresh removed

The touch handler in Twenty Twelve's navigation.js, added in [28700] for https://core.trac.wordpress.org/ticket/24767, is delegated from body. 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. 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.

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.

#16 @sukhendu2002
3 weeks ago

Following up on comment:14: I re-tested on trunk with supported browsers (Chrome and WebKit/iOS Safari, touch emulation) and narrowed down the cause. It differs per theme.

Results (first tap on a parent menu item, viewport ≥ breakpoint)

Theme Chrome WebKit
Twenty Twelve follows parent link ✗ follows parent link ✗
Twenty Thirteen opens sub-menu ✓ opens sub-menu ✓
Twenty Fourteen opens sub-menu (synthetic hover) follows parent link ✗

This corrects part of my comment:13: Twenty Thirteen works as expected on trunk.

Root cause

Twenty Twelve: this is a regression of #24767 caused by a browser change. [28700] originally bound the handler directly to the links. [30746] then switched it to delegation from body, so that it would also cover .page_item_has_children:

$('body').on( 'touchstart.twentytwelve', '.menu-item-has-children > a, .page_item_has_children > a', function( e ) {

That worked in 2014, but since Chrome 56 (2017) and iOS Safari 11.3 (2018), touchstart listeners on window, document and body are passive by default. That means e.preventDefault() is ignored. Chrome logs:

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

The 'ontouchstart' in window check is not the problem: it returns true in both browsers. Twenty Thirteen works because its handler is attached directly to the links, which are not treated as passive.

Twenty Fourteen: it has no touch handler at all, and relies on the browser simulating hover. That is tracked in #30575. Note that both open PRs there also delegate from document.body. I tested PR 9291 and the first tap still follows the parent link in Chrome and WebKit. I'll follow up on #30575 separately.

Patch

PR: ​https://github.com/WordPress/wordpress-develop/pull/14983

The PR fixes Twenty Twelve only:

  • Delegate the handler from .main-navigation instead of body. This keeps the selectors from [30746], and a listener there is not passive, so preventDefault() works again.
  • Only intercept the tap at (min-width: 600px), where sub-menus are hidden behind hover. Below that, the toggle menu already shows sub-menus, so a parent link still follows on the first tap. (Without this guard, the fix would bring back the double-tap side effect mentioned in ticket:30575#comment:8.)
  • Bump the navigation.js version.

Regarding the Twenty Fifteen-style disclosure button I suggested in comment:13: given the root cause, I think that's better handled as a separate accessibility enhancement than as a blocker for this fix.

Note: See TracTickets for help on using tickets.