bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Dropdown menus don't get closed when selecting an option

Open lrlopez opened this issue 14 years ago • 21 comments

[Tested on Chrome 21, Safari 6 and Firefox 14]

I've upgraded Bootstrap on a test-branch and dropdown menus no longer close automatically once an option is selected. User has to click outside for the menu to disappear.

The problem is reproducible in the official docs: http://twitter.github.com/bootstrap/javascript.html#dropdowns

Did I miss something on the changelog about this new behaviour? If this is a "WON'T FIX", is there any workaround to force them to close?

lrlopez avatar Aug 21 '12 10:08 lrlopez

I have the same problem. Dropdowns used to close automatically when selecting an option, after upgrade to 2.1.0 they do not close anymore when an option is selected.

kr3l avatar Aug 22 '12 16:08 kr3l

I have several dropdown into a navbar and it's always the first initialized who works well. Others do not want to close when I choose (click) an option OR if I click somewhere else on the page to close it.

The problem is here since the 2.1 version.

lphm avatar Aug 23 '12 13:08 lphm

Hi,

Same problem for me :

http://jsfiddle.net/7ptXA/

jon301 avatar Aug 23 '12 13:08 jon301

I've commented on the line of code that caused this here: https://github.com/twitter/bootstrap/commit/c9cef741f6d97bb8549af8e4809fccce4339f2f4#js/bootstrap-dropdown.js. Change the target for the event to ".dropdown form" and it should be fixed.

zachlowry avatar Aug 23 '12 14:08 zachlowry

@zachlowry This fixes the issue for me, thanks

kr3l avatar Aug 23 '12 16:08 kr3l

Removing "form" from the selector also prevents menu items using rails jquery_ujs from working (e.g. :method => :delete for a sign out link).

jasonkreider avatar Aug 23 '12 16:08 jasonkreider

+1 on this issue

mhuggins avatar Aug 23 '12 21:08 mhuggins

+1 on this issue

internalfx avatar Aug 24 '12 18:08 internalfx

Here's an interim solution until the 2.1.1 comes through:

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

Edit: I should add, in case it's not clear, that this workaround is really only intended for those loading Bootstrap off a CDN. If you're hosting your own code, just fix it directly. :P

mfansler avatar Aug 26 '12 05:08 mfansler

Thanks for the workaround!

mhuggins avatar Aug 26 '12 14:08 mhuggins

+1 on this...

benrhere avatar Aug 27 '12 12:08 benrhere

+1 for me too. Glad I'm not the only one that was confused.

tonybruess avatar Aug 27 '12 14:08 tonybruess

I'm somewhat confused as to why 4756 was closed - the fix listed above does NOT fix that specific issue?

EDIT: Never mind, probably in reference to 4550

ShivX avatar Aug 27 '12 20:08 ShivX

added the form bit back, which fixes this – will look into another way of handling the mobile stuff

fat avatar Aug 28 '12 04:08 fat

@fat - I'm not seeing the commit in the Github commits that fixes this. Am I missing something?

mhuggins avatar Aug 29 '12 21:08 mhuggins

@mhuggins It's on the wip branch: https://github.com/twitter/bootstrap/blob/2.1.1-wip/js/bootstrap-dropdown.js

mfansler avatar Aug 29 '12 22:08 mfansler

Ahh, didn't realize that's how Twitter does it. Thanks!

mhuggins avatar Aug 30 '12 16:08 mhuggins

A temporary workaround can be found here for incompatibilty with jquery-rails while waiting 2.1.1 release : https://github.com/seyhunak/twitter-bootstrap-rails/issues/343

ybart avatar Aug 31 '12 15:08 ybart

the same issue

RusAlex avatar Oct 10 '12 11:10 RusAlex

$('.dropdown-menu select, .dropdown-menu textearea').click(function(e) { e.stopPropagation(); })

marcelometal avatar Apr 06 '13 00:04 marcelometal