• I’ve noticed that when a main menu has a sub-item menu option, the main menu option needs to be double-tapped on my Android mobile phone. You should be able to replicate this on a mobile device on the preview build (wp-themes.com/argent).

    On the preview build, after tapping on “MENU,” you should only have to tap once on “ABOUT” and “SUB-PAGE” to load them, but you should have to tap twice to load “PARENT PAGE.”

    This is causing serious issues with confusing mobile users trying to navigate my site, unfortunately, and I am very interested in how it can be fixed. Googling leads to a lot of articles about how hover causes this issue on iOS devices, but I’m encountering this on an Android (version 9) device, using Chrome (current version: 75.0.3770.143).

    That said, I went through the style.css sheet and removed all the references to “hover”, anyways, just to see if that would fix the issue, but it did not appear to resolve it.

    Any ideas or suggestions are very welcome!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter hastibe

    (@hastibe)

    Okay, I think I figured it out…

    Removing the code below (in argent > js > navigation.js) appears to resolve the issue on mobile devices, but creates an issue on tablets (where the size of the screen hasn’t triggered the mobile menu style), as you can’t hover to display the sub-menu items without the code below.

    Ack, anyone have suggestions for a solution for this?

    From here: “This patch allows the user to view a site on a touch screen tablet and access child menus by clicking on the parent once, or access the parent by clicking on it twice.”

    	// Fix child menus for touch devices.
    	function fixMenuTouchTaps( container ) {
    		var touchStartFn,
    			parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item-has-children > a' );
    
    		if ( 'ontouchstart' in window ) {
    			touchStartFn = function( e ) {
    				var menuItem = this.parentNode;
    
    				if ( ! menuItem.classList.contains( 'focus' ) ) {
    					e.preventDefault();
    					for( var i = 0; i < menuItem.parentNode.children.length; ++i ) {
    						if ( menuItem === menuItem.parentNode.children[i] ) {
    							continue;
    						}
    						menuItem.parentNode.children[i].classList.remove( 'focus' );
    					}
    					menuItem.classList.add( 'focus' );
    				} else {
    					menuItem.classList.remove( 'focus' );
    				}
    			};
    
    			for ( var i = 0; i < parentLink.length; ++i ) {
    				parentLink[i].addEventListener( 'touchstart', touchStartFn, false )
    			}
    		}
    	}
    
    	fixMenuTouchTaps( container );
    • This reply was modified 6 years, 8 months ago by hastibe.
    Thread Starter hastibe

    (@hastibe)

    It seems like one possible solution is to have the JavaScript above run only on screen widths larger than the breakpoint size (767px) from the mobile menu to the tablet and desktop menu.

    I’m not familiar with JavaScript, so I don’t know how to implement this, though. Could something like this be used (and if so, could anyone show me how to format it)?

    jQuery(document).ready(function(){
        function resizeForm(){
            var width = (window.innerWidth > 0) ? window.innerWidth : document.documentElement.clientWidth;
            if(width > 767){
    
            } else {
    
            }    
        }
        window.onresize = resizeForm;
        resizeForm();
    });

    Source: https://stackoverflow.com/questions/30947430/best-way-to-have-a-javascript-load-only-on-desktop-version-of-site

    Thread Starter hastibe

    (@hastibe)

    Following this Window matchMedia() Method (specifically the example given at the bottom of the tutorial), I made the changes below to the problematic JavaScript.

    Is this a workable solution? It works for me, in that on my phone, I no longer need to tap twice to load parent menu items that have child menu items, and on my tablet, tapping once on the parent menu item displays the child menu items, and tapping twice loads the parent menu item, but I don’t know enough to know if this is an appropriate way to solve the problem.

    // Fix child menus for large touch devices.
    function myFunction(x) {
      if (x.matches) { // If media query matches
        function fixMenuTouchTaps( container ) {
    		var touchStartFn,
    			parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
    
    		if ( 'ontouchstart' in window ) {
    			touchStartFn = function( e ) {
    				var menuItem = this.parentNode;
    
    				if ( ! menuItem.classList.contains( 'focus' ) ) {
    					e.preventDefault();
    					for( var i = 0; i < menuItem.parentNode.children.length; ++i ) {
    						if ( menuItem === menuItem.parentNode.children[i] ) {
    							continue;
    						}
    						menuItem.parentNode.children[i].classList.remove( 'focus' );
    					}
    					menuItem.classList.add( 'focus' );
    				} else {
    					menuItem.classList.remove( 'focus' );
    				}
    			};
    
    			for ( var i = 0; i < parentLink.length; ++i ) {
    				parentLink[i].addEventListener( 'touchstart', touchStartFn, false )
    			}
    		}
    	}
    
    	fixMenuTouchTaps( container ); 
      } 
    }
    
    var x = window.matchMedia("(min-width: 768px)")
    myFunction(x) // Call listener function at run time
    x.addListener(myFunction) // Attach listener function on state changes

    Hi there,

    Are you seeing any side effects to your site once you added that code? if not, I think it should be a solid way to solve the issue.

    Do you mind providing the URL to your site? I would like to test it out on my iPhone to see if I can pick up on anything.

    Thanks,

    Thread Starter hastibe

    (@hastibe)

    @darnelldibbles – thanks for the response! I’ve just added the code to a test site for now, and haven’t encountered any side effects, but I’ve only been able to test it on a few different devices (desktop, Android phone, and iPad). I just e-mailed you a link and password to access the test site, and would definitely be interested in knowing if the modified code holds up for you.

    I’ve temporarily disabled the // Fix child menus for touch devices. code on my main site, but if you are interested in seeing the issue on Argent without the modified navigation menu code, here are two sites that exhibit the double tap (on mobile menu items that have child menu items) behavior: wp-themes.com/argent and http://www.newtonproject.eu.

    Hope this is helpful and looking forward to hearing back!

    Thread Starter hastibe

    (@hastibe)

    Any updates, @darnelldibbles? If you’ve had a chance to test it out, and all is looking good, I will implement the code on the production site.

    Hi there,

    We’re not able to advise you on your code.

    I’ve noticed that when a main menu has a sub-item menu option, the main menu option needs to be double-tapped on my Android mobile phone

    I’m able to replicate this issue in Chrome and Opera on Android for both the WordPress.com and self-hosted version of this theme, so I’ve reported it to our theme developers in https://github.com/Automattic/themes/issues/1191

    If you think you have a patch that fixes the issue, you’re welcome to submit a pull request in that repository, and our developers will take a look at your proposed fix.

    If you want to add your code to your own site, that’s your prerogative, but we cannot help with your fix, nor anything your custom code might break.

    I just e-mailed you a link and password to access the test site, and would definitely be interested in knowing if the modified code holds up for you.

    Not sure how you emailed someone from a forums post, but both asking for and providing login credentials for a site, whether production or staging, goes against the guidelines for this forum, so please do not do that.

    Thread Starter hastibe

    (@hastibe)

    Thanks for reporting the issue to the theme developers, @kokkieh, and I do think my patch fixes the issue, so I will see if I can submit a pull request.

    Thanks, too, for letting me know about not asking for or providing login credentials–what I shared was the access code to a testing site that is hidden behind a wall using the Hide My Site plugin, so that it’s not accessible to the general public. I didn’t provide any credentials that would allow someone to log-in as a user on the site, but is providing access codes to testing or staging sites that aren’t otherwise generally available to the public also not allowed? If so, I will make sure not to do that again on these forums.

    From the guidelines I linked to above:

    Do not post login information, even test IDs and test passwords.
    Do not ask for any kind of access in order to provide support, not even for plugins or themes.

    Interpretation and enforcing of those guidelines are up to the moderator team, but taken at face value I’d say that’s not allowed.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Menu Double Tap Issue on Mobile (Android 9)’ is closed to new replies.