Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dropdown] Submenus not working on mobile [with possible solution] #3183

Closed
timothyarmes opened this issue Oct 14, 2015 · 5 comments
Closed
Milestone

Comments

@timothyarmes
Copy link

Hi,

Dropdown submenus don't work on mobile devices. They open, but you can't click on the items.

Having spent a couple of hours trying to track this down, I've finally figured out what's happening:

In dropdown.js, when touch events are available they are bound to the mouse enter event:

.on('touchstart' + eventNamespace, selector.item, module.event.item.mouseenter)

Now, whenever there's a touch event, the handler is called. Note that this doesn't happen on a standard browser. Here's the handler:

mouseenter: function(event) {
  var
    $subMenu    = $(this).children(selector.menu),
    $otherMenus = $(this).siblings(selector.item).children(selector.menu)
  ;
  if( $subMenu.length > 0 ) {
    clearTimeout(module.itemTimer);
    module.itemTimer = setTimeout(function() {
      module.verbose('Showing sub-menu', $subMenu);
      $.each($otherMenus, function() {
        module.animate.hide(false, $(this));
      });
      module.animate.show(false,  $subMenu);
    }, settings.delay.show);
    event.preventDefault();
  }
},

When the users taps on an item in the submenu two things now happen:

  1. The mouseenter is called for the .item. The code checks for another submenu and exits if there isn't one. So far so good...
  2. The mouseenter is then called again, this time for the parent menu item (presumably the event is bubbling up the chain). This time the handler finds a submenu, calls the show submenu code (pointlessly, since it's already open), and then calls event.preventDefault().

Since event.preventDefault() is called, no further events are generated and the click event is hander is never called.

Commenting out the event.preventDefault() appears to solve the issue, but I don't know if there are other repercussion that need to be taken into account.

@jarrettv
Copy link

I am also seeing this issue.

@meteorimpact
Copy link

Commenting out that line seems to work perfectly. I've not seen any other issues as a result.

@ghost
Copy link

ghost commented Jan 12, 2016

I have this issue as well.

@jlukic jlukic added this to the 2.1.9 milestone Jan 12, 2016
@jlukic jlukic changed the title Submenus not working on mobile [with possible solution] [Dropdown] Submenus not working on mobile [with possible solution] Feb 15, 2016
@jlukic
Copy link
Member

jlukic commented Feb 15, 2016

Thanks everyone for your patience here. I apologize for the delays on a fix.

Mobile was triggering mouseenter (show sub-menu) events from touchstart, this was causing an issue where the bubbled event would trigger the parent menus show sub menu and prevent proper selection.

jlukic added a commit that referenced this issue Feb 15, 2016
@jlukic jlukic closed this as completed Feb 15, 2016
@ghost
Copy link

ghost commented Feb 15, 2016

don't mention it 👍 good work takes time

@jlukic jlukic modified the milestones: 2.1.9, 2.2 May 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants