My menus are working and look correct. The problem is on touch devices (iPad for example) that, once opened (single touch), they don't close. If you are looking through the menus and don't find what you need, you have to refresh to go back to your page. If you touch outside the menu, they stay open. This has come up in user testing as a problem for new users, especially those new to touch devices.
Is there a way to have them close after a set time or if you touch outside the menu? I'm not that good with js, so I'm not even sure where to begin.
I'm using TB_Megamenu 7.x-1.0-beta2+0-dev with a subtheme of Adaptive Themes Corolla. I have applied the following patches to tb_megamenu in case that matters:
#2011042: Menu doesn't open on a tablet
#2053875: Menu items loosing attributes
Thanks in advance for an help you can offer or even confirmation that this is the expected behavior.
Heidi
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | 2285435-21.tb_megamenu.Closing-menu-on-touch-device.patch | 3.32 KB | knaffles |
Comments
Comment #1
mazz0016 commentedI am having this problem too. Has anyone found a solution to it yet?
Thank you
Comment #2
hwasem commentedI haven't found a solution yet, @mazz0016
Comment #3
mazz0016 commented@hwasem: I have found a solution. I figured out that there were 2 spans called class=toggle. Both had identical looking parents, however only the second one had the complete structure of the menu. Both spans and their parents were stacked on top of each other. The second span is nested in the first span. When the MENU icon was clicked, the first span and it's parent were targeted and the menu would then expand as expected because the first span was then hidden and the user could then view the menu underneath because the second span (containing the menu) could display. However because there were 2 spans of the same class name and identical looking parents, the code assumed the first span and it's parent were then being targeted again in the javascript when the user clicked the MENU icon again to close. And because the first span was now hidden and the javascript was targeting only the first span, the toggleClass in the javascript wasn’t removing the ‘responsive-toggled’ class, therefore the menu wouldn't close. The second span needed to be targeted in the javascript because it was the one that was open and getting the click event, but ‘responsive-toggled’ class needed to be removed from it’s great grand parent div to close it, not it’s parent.
responsive_menus_simple.js:
The way this works is the condition statement evaluates to see if the second span has been opened. The first time it goes through the user has clicked on the first span (The spans were stacked on top of each other only the first span is accessible the first time) and thus the user has not clicked the second span, so the else will run. The first span will be hidden and the second span will be reveled underneath. The menu is now expanded. The second time it goes through the second span is open so the condition is now true and the first scenario is run. Closing the second span. Since the second span is nested in the first span. We must target the great-grandparent to close the menu.
Comment #4
hwasem commentedThanks for the update, @mazz. I am actually using the full TB_Megamenu on the iPad(modified collapsing breakpoints in css), not the collapsed mobile version. Your update will likely help someone else in the future, though. I had to go to Mobile Navigation module for a collapsed menu at the phone viewport and that is working correctly when I open/close with the ☰ button, thankfully.
So following the logic you found in the TB_Megamenu mobile menu, I'm wondering if I might be able to figure out the tablet viewport problem with the full menu. Are you just using Firebug or Inspect Element in your browser to see the HTML code at the smaller size? Or are you using something to help simulate the touch environment? I can't get Safari to install on my Windows 8.1 tablet, but I was able to get Chrome. It isn't having the same problem with menus staying open as the Kindle on iPad (using Chrome even on iPad they stay open). I'm trying to figure out how to troubleshoot a problem I can't replicate in a full-featured browser. I wish I could get the element inspection to work on the iPad.
Is responsive_menus_simple.js a new js file you created to fix this problem?
Thanks,
Heidi
Comment #5
ankit agrawal commentedThe toggle (close state) is still not working specially in the mobile devices, has anybody found a workaround for it?
I guess the solution suggested by the @mazz0016 is for the tb_sirate and that is using the in built tb_mega_menu for rendering the menu, responsive_menus_simple.js seems to be the file of that theme only.
Comment #6
hwasem commentedStill looking into this. I found the demo site for tb_sirate and it is not closing menus on iPad landscape either. So it is not unique to me or my theme. Good to know, I guess.
Comment #7
dsrikanth commentedExperiencing same issue. For now, I just added a quick jQuery workaround.
(function($) {
Drupal.behaviors.drupaldeveloper = {
attach: function (context) {
$('a.dropdown-toggle').focusout(function() {
$(this).parent('li').removeClass('open');
})
}
}
})(jQuery);
Comment #8
hwasem commented@dsrikanth, is this in your own custom .js file or somewhere else? I'm can't seem to get that to work on iPad in my theme's custom js.
Comment #9
dsrikanth commentedYes, its in my custom js. I am sorry its not working for you. Not sure how helpful this is but I am working on making the menu more keyboard accessible as well (and thus changing my custom jQuery completely). Here is that I have - its not complete but does few things well. Hope this helps!
Comment #10
hwasem commented@dsrikanth, I'm curious. Are you seeing the problem only on iOS or with other touch devices, too? I tested Kindles with current version (7.x-1.0-beta5 with patch #2011042: Menu doesn't open on a tablet) and it appears to be fine. I only have Kindles and iPads to test on, unfortunately.
I have tried to use your code, but I couldn't get it to work.
Instead, I think this will work for me in my custom theme .js file:
So far I'm not seeing any negative impact and my Kindles/desktops are still working as expected. Do you see a problem with doing it this way?
Heidi
Comment #11
dsrikanth commentedHmm interesting. I am working on TB Mega menu 7.x-1.0-beta3 on Bootstrap theme 7.x-3.1-beta2 and jQuery 1.9.
And I have tested this on several iOS devices, Android devices and Windows phones as well..
Comment #12
E Johnson commentedHey dsrikanth,
Thanks for the solutions in #7 and #9. It seems to work for me on mobile device.
Also, adding this code (https://www.drupal.org/node/2274909#comment-9071921) helped solve having to hit level-1 menu items twice to expand the sub-nav.
Hope this helps someone in the future. Adding this comment so I can remember this fix for future projects.
Comment #13
neschi commentedI've fixed it with this little code, just put it on a custom JS file. I hope you find it useful.
Best regards!
Comment #14
nickap commented#13 worked great, thank you! I had an additional problem though, which was that not only were menus not closing if you clicked again on the same top menu item, but they also would not close if you clicked on a different menu item - so if you click on menu item 1, and the submenu for that item appears, then you click on menu item 2 without first closing submenu1, then submenu1 would stay open and the submenu for item 2 would appear stacked over the top of submenu1. So I just altered the code from #13 very slightly to close all submenus when any top menu item is clicked, then open the submenu for just the clicked item. (Since I'm a JQuery idiot, I'm also including here the 'on document ready' code that is required for the function to work. The code below, copied and pasted directly into JS Injector, solved all menu problems for me on touch devices.)
Comment #15
saifullah.akber commentedhwasem you solution worked for me. No problem so far. Thank you :)
Comment #16
saifullah.akber commentedComment #17
sempke commentedi have include de js-code from hwasem an also neschi in js injector by drupal.
It doesn't work on IPAD.
The dropdown still not close when you touch the screen somewher!!!
Comment #18
sempke commentedif this does not work on iPad, please take TB MEGA MENU off the market from drupal !
Comment #19
caminadaf commentedHello all, I've created a patch for this module to resolve this issue and maintain all of the old functionalities.
Now if a link has a submenu, you can open and close the menu freely.
If you click anywhere outside the meganav, all of the menus are closed.
Comment #20
andrewozoneComment #21
knaffles commentedI tested the patch in #19, but it didn't work for me for a couple of reasons:
The attached patch provides the ability to tap on another top level menu item, or tap away from the menu (ie, anywhere else on the screen) in order to close the currently open menu item. Testing should be performed on both touch desktops and iOS.
Comment #22
scorbine commentedComment #24
knaffles commented