twbs / bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
https://getbootstrap.com
MIT License
170.29k stars 78.79k forks source link

Button dropdown links don't work on mobile (android, iOS) #4550

Closed MikiMullor closed 11 years ago

MikiMullor commented 12 years ago

I have simple dropdown buttons we built with 2.04

links are A tags, proper quotes, href='#'

Used to work fine.

Upgraded today to 2.1 and the links in any dropdown button don't work. The dropdown menu opens, but clicking on a link closes the menu without any action. tested on Android 2.3 and iOS 5

Rolledback to 2.04 and everything works again. Anyone else has this issue?

Stefac commented 12 years ago

Same problem here for me. Menu opens, but clicking simply close it. Tested on iPad IOS 5.1

jwilson commented 12 years ago

Would like to add that the dropdown menus from a navbar do work on a iPad (iOS 6), but like the other 2 posters they are not working on a dropdown button.

dpwolf commented 12 years ago

A quick hack to prevent the dropdown menu from being cleared on touch devices:

on line 143 of bootstrap-dropdown.js replace

.on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus)

with

.on('click.dropdown.data-api', clearMenus)

You won't be able to tap outside the menu to close it, but the dropdown links will work.

ShivX commented 12 years ago

+1

Looking forward to the fix in 2.1.1

fat commented 12 years ago

Hey @MikiMullor,

Thanks for opening this issue! Unfortunately, it looks like it fails to pass the criteria neccessary for submitting to bootstrap. The following things are currently failing:

For a full list of issue filing guidelines, please refer to the bootstrap issue filing guidelines.

thanks!

ShivX commented 12 years ago

@fat

This seems counter-productive. The issue can be repeated on the bootstrap sample page, and it's pretty critical that Bootstrap button dropdown links don't work on touch devices! :-/

If it means getting it fixed in 2.1.1, Here's a JSFiddle

dpwolf commented 12 years ago

@ShivX thanks!

Zylinderkatze commented 12 years ago

+1 here.

Looking forward to the fix. Any foreseeable release date for it?

  Edit: For those interested, this is my little "workaround" that seems to work, add it after the "bootstrap-dropdown.js" include (I put mine in the $(function() { } section which is located at the end of the page in my case):

$('a.dropdown-toggle').on('touchstart', function(e) {
      // do your stuff here
})
Starefossen commented 12 years ago

Still an issue in 2.1.1. Demo can be found in gh-pages.

babrewer commented 12 years ago

Have also tested with 2.1.1. Dropdown menu links do not work on IOS devices running 5.1.1. They work fine when using RWD Bookmarklet or responsive.is for testing, just not natively on IOS devices.

mikegreiling commented 12 years ago

I'm having this issue too. Very much interested in a fix.

dcorb commented 12 years ago

Having the issue in Chrome Desktop with v.2.1.1 @dpwolf solution worked for us (aka removing touchstart event in that line).

The problem is that both events 'click' and 'touchstart' are triggered. First "touchstart" event and then, 300 ms later comes up the 'click' event .. so clearMenu is called twice.

Probably I'm wrong.. but it's like the browser doesn't have time to handle the 'a' link as normally because touchstart already cleared the menus.

Is there any other solution than treat those 2 event types separetly ? More info https://developers.google.com/mobile/articles/fast_buttons?hl=de-DE

patrickoehlinger commented 12 years ago

Same problem for me with Bootstrap 2.1.1 on iOS 6 :-(

tonybruess commented 12 years ago

I'm experiencing this issue as well :(

thezoggy commented 12 years ago

Pull #4812 looks to address this

thoughtshop commented 12 years ago

Pull #4812 didn't fix dropdown links on iOS for me. It seems the default event is still being prevented.

crag commented 12 years ago

Also have this problem on IOS 6.

blakeembrey commented 12 years ago

I'll fix this up in my PR later today. Shouldn't require too much of a change to get this working as expected.

stevecoug commented 12 years ago

I seem to have a better workaround by adding this line after the line dpwolf mentioned, rather than changing the line:

$('.dropdown-menu').on('touchstart.dropdown.data-api', function(e) { e.stopPropagation() })

I haven't noticed any side effects so far.

blakeembrey commented 12 years ago

@fridgesm Pretty much the same thing I did for my fix in #5067 - However you should bind it to the body otherwise it won't get triggered on any dropdowns after you call that line. Should be a better solution to this, just can't think of on right now

tetherit commented 12 years ago

Added this to my bootstrap_custom.js.coffee file in app/assets/javascript:

  $('.dropdown-menu').on('touchstart.dropdown.data-api', (e) ->
    e.stopPropagation() )

Dropdown menu items now work on iOS :D - Thank you fridgesm for suggesting this.

ercchy commented 12 years ago

well my solution was to add class dropdown to the parent tag on HTML markup. If you have access to it and are able to change it I would recommend doing that, so you don't have to do a js workaround

babrewer commented 12 years ago

Like this: <div class="btn-group dropdown"> <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">

If so, that doesn't work for me.

ercchy commented 12 years ago

My markup looks like this:

 <div class="dropdown btn-group">
      <button class="btn gradient dropdown-toggle" data-toggle="dropdown" id="login">
        Login
      <span class="caret"></span>
       </button>
       <ul class="dropdown-menu">
           <li><a href="some-link">Dropdown1</a></li>                    
       </ul>
</div>

but I am not using any js to initialize behavior. Sometimes it helps if u switch class.

babrewer commented 12 years ago

That doesn't work on my end, not sure what I'm missing, but thanks for the assistance.

foo4u commented 12 years ago

+1

Here's a jsfiddle demonstrating the problem against 2.1.1.

rraz-np commented 12 years ago

Has anyone worked around this issue? workaround mentioned by @fridgesm does not fix the issue in android browser.

blakeembrey commented 12 years ago

@rabiraj In what way doesn't it work? If you are creating the dropdown menu after you add that fix, it won't work. Which is why I said to add it to the body tag. E.g.

$('body').on('touchstart.dropdown', '.dropdown-menu', function (e) { e.stopPropagation(); });
rraz-np commented 12 years ago

thanks, @blakeembrey , earlier I tried $('.dropdown-menu').on('touchstart.dropdown.data-api', function(e) { e.stopPropagation() }) which did not work. Using $('body').on('touchstart.dropdown', '.dropdown-menu', function (e) { e.stopPropagation(); }); as you suggested seems to fix the issue for me.

Also, I noticed with or without the fix, sometimes the dropdown do not open. To test, create 3 dropdown buttons on navbar and touch all the dropdown buttons quickly. It does not open dropdown sometimes.

It may also be the problem due to click and touch. Any suggestions?

james3burke commented 12 years ago

The 4812 patch fixed the problem for me on navbar dropdowns (tested on android chrome), but not dropdowns for other buttons. As mentioned by @ercisson earlier though adding 'dropdown' to the class of the parent tag fixed normal buttons too. This doesn't match the documentation on the twitter bootstrap 'Components' page, but it gets the job done. I've not touched the javascript at all.

blakeembrey commented 12 years ago

@james3burke Could you test #5067 in the same conditions? It's my latest PR and should have all the same fixes found in the issue you just mentioned. Plus I am not sure whether adding .dropdown would fix the issue in the latest version, as that code is now targeting block event propagation on .dropdown form.

danielspangler commented 12 years ago

@blakeembrey I'm new to this thread, but I just tried #5067 on a scenario that wasn't working with some of the other suggestions on this thread and it's working fine now on ios. It also fixed another seemingly unrelated javascript error I was getting on ios when dynamically adding content to the dom and showing it as a modal within a button click handler.

focalstrategy commented 12 years ago

Here's a super minimal test case: http://jsfiddle.net/DSjDa/

I've inlined the CSS and JS, but it's clear that it doesn't work.

dieselcz commented 12 years ago

My workaround is to divide this line in bootstrap-dropdown.js:


.on('click.dropdown touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })

into two lines:


.on('click.dropdown', '.dropdown form', function (e) { e.stopPropagation() })
.on('touchstart.dropdown.data-api', '.dropdown', function (e) { e.stopPropagation() })

Tested on android 2.3

auxbuss commented 12 years ago

+1 on 2.1.1

I've reverted to 2.0.4 js for now

pixelbind commented 12 years ago

@dieselcz - your solution worked for me on iOS6 with Safari and Dolphin. Thanks!

danielfranz commented 12 years ago

This is what worked for me:

$('a.dropdown-toggle, .dropdown-menu a').on('touchstart', function(e) {
  e.stopPropagation();
});

It also makes dropdown menus that are submenus work as expected on touch devices.

Bossa573 commented 12 years ago

@danielfranz That's works form me too, thanks! the dropdown menu won't disappear when I click the blank area, at least the link under the menu can be clicked now

dieselcz commented 12 years ago

@pixelbind Glad to help.

abhisec commented 12 years ago

Is this assigned to somebody and will we see a fix in 2.2?

dmcycloid commented 12 years ago

yep, @dieselcz solution(https://github.com/twitter/bootstrap/issues/4550#issuecomment-8684262) working Android 4.1 Chrome & iOS 6 Safari

andrewdeandrade commented 12 years ago

Hey @MikiMullor,

Thanks for opening this issue! Unfortunately, it looks like it fails to pass the criteria neccessary for submitting to bootstrap. The following things are currently failing:

For a full list of issue filing guidelines, please refer to the bootstrap issue filing guidelines.

thanks!

briankiewel commented 12 years ago

@malandrew there are already 2 jsfiddles linked in here.

stevecoug commented 12 years ago

@malandrew,

How is this not a critical issue? Dropdowns are completely non-functional on touch devices, and you guys are splitting hairs about filing guidelines? We're all trying to figure out how to fix the issue ourselves, without any help from the core team, on an issue that should be a roadblock.

If touch devices such as iOS and Android are not considered core functionality, then please tell me now so I don't waste my time.

maimairel commented 12 years ago

This malandrew guy is just spamming, he just copy pasted what he wrote above on almost every open issues..

ivos commented 12 years ago

+1

Experienced on Android 2.3.5, BS 2.1.0.

andrewdeandrade commented 12 years ago

Sorry about what looks like spamming. I was playing around with the bootstrap Makefile on my computer and it looks like whatever happened is the sideeffect of running make haunt. I didn't expect any sideeffects of exploring the makefile options to propagate to dozens of issues on github.

@fat if someone else runs make haunt they'll end up causing this problem accidentally.

artiz commented 12 years ago

Please skip commit fbccd6b - it was invalid

thezoggy commented 11 years ago

rebase and force push

Hillshum commented 11 years ago

Because the only workaround listed that actually worked for me was https://github.com/twitter/bootstrap/issues/4550#issuecomment-7987654 I ended up just writing my own event handlers for the links in question that used window.location