I am using a Bootstrap dropdown menu. The problem is that it never drops down upon the first click; I need to click 2 times for it to be toggled. I guess the click event is somehow getting stuck somewhere before propagating down...
Is there any way to fix that?
In my case, the other answers don't work.
In
application.js
, I had:Removing bootstrap-sprockets fixed the problem.
If someone is using angular with
ui-bootstrap
module along with normal bootstrap HTML dropdown definition, there are also two clicks needed.=> Removing the
data-toggle="dropdown"
will fix the issue.Opening the dropdown with one click will work after this.
Reference: https://github.com/angular-ui/bootstrap/issues/2294
In Bootstrap 4,
bootstrap.min.js
andbootstrap.bundle.min.js
now conflict in dropdown.By removing
bootstrap.min.js
, the dropdown double click issue will resolved.This happens because the Twitter Bootstrap syntax for their drop downs include a
href
tag. You will need topreventDefault
andstopPropagation
to prevent this from happening. Something like this will do the trick:By looking within the source code of angular.ui.bootstrap and the native bootstrap.js they have both handlers for dropdowns.
Proposed Solution: adjust angular.ui.bootstrap dropdownToggle directive restrict only to "A" attributes. so by resolving this issue you need to modify dropdownToggle restrict "CA" into "A" this will hide Class looker from angular.ui.bootstrap which has been already handled by bootstrap.js
for the minified version of angular.ui.bootstrap look for this line directive("dropdownToggle",function(){return{restrict:"CA",require:"?^dropdown",link:function(a,b,c,d){
replace "CA" with "A".
Cheers
I had the same issue as jaybro in https://stackoverflow.com/a/27278529/1673289, however their solution didn't help.
The way to fix for both cases was to add:
onto the element which has the
data-toggle="dropdown"
attribute.I found that on some pages I would have to double click and other pages were single click.
Removing
data-toggle="dropdown"
made the double clicks into single and broke the singles.I compared the html in the dev tool (because the same html is being served) and found on my double click pages the div with data-toggle looked like this:
But the single click html looks like this:
So, in the document ready, I used attr detection and the prevent default answer and it made my double click opens into single click opens:
This may also happen if you have more than one bootstrap.js files! Check if you still have an older version and remove that script.
In BootStrap 4, One should not include both "bootstrap.bundle.min.js" and "bootstrap.min.js". This will cause the DropDown issue. Only Keep "bootstrap.bundle.min.js" as it will have all required code.
Not the answer you're looking for? Browse other questions tagged javascript css angularjs twitter-bootstrap angular-ui-bootstrap or ask your own question.
asked
viewed
25,739 times
active
3 months ago
Linked
Related
Hot Network Questions