-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
using .dropdown('toggle') twice in JavaScript doesn't return the dropdown to its original state #10486
Comments
For future reference, a JS Bin or JSFiddle is preferred. |
I'm working on a major US retail site and need this to work. Is there a workaround or patch? This bug is a month old and, while it's not critical (as in halting the browser), it's still fairly major as something very fundamental is not working. |
There are two problems here. The first is the dropdown usage documentation. It says that there are 2 ways to use the dropdown:
The other problem is (most likely because it's not working) with the gist. You have 2 click events on the same menu item which, after you've clicked it, will now run twice. Once on the click and once on the toggle essentially opening and closing the dropdown. Solution: For now, use the |
@devinmcinnis No, actually, "toggle" doesn't toggle. The problem is here: https://github.com/twbs/bootstrap/blob/master/js/dropdown.js#L42 and here https://github.com/twbs/bootstrap/blob/master/js/dropdown.js#L53 Bootstrap only toggles the "open" class if it's already set. So sending the "toggle" message doesn't actually "toggle" the class, so the widget doesn't ever close -- it just stays open. I think it'd be pretty easy to throw an else on that if to clear the class. As an aside, I've personally worked around this problem by toggling the class manually. |
@evanp Bootstrap toggles the "open" class if it's not set. It will remove the "open" class if it is set. The quick fix for this would be to set toggle:
The problem would then be that every dropdown would be initialized on load and that's probably not desired (but I also don't know a use case where you wouldn't want a dropdown initialized). |
Yokay. It's been a while since I submitted this issue; I'll go back in and review the exact cause of the problem. In the meanwhile, can you put together some sample code that successfully toggles a dropdown on and off via Javascript? |
You can use the data-attribute and |
added a note to the docs about the reliance on the data attribute, hope that helps – thanks @devinmcinnis for the support |
If you use the JavaScript interface for dropdown -- .dropdown("toggle") -- multiple times, the "open" class isn't cleared, so the dropdown stays open.
https://gist.github.com/evanp/6456479
The text was updated successfully, but these errors were encountered: