You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
toggle doesn't close the dropdown if there are no [data-toggle="dropdown"] #26420
dropDownMenu <ul> element contains both dropdowndropdown-menu
first point: toggle method open it (btw dropdown class is vital there, without it plugin doesn't work - why?)
second point: toggle doesn't close it.
Through debugger I see this logic
// bootstrap dropdown code
var context = $$$1(toggles[i]).data(DATA_KEY);
var relatedTarget = {
relatedTarget: toggles[i]
};
if (!context) {
continue; // here we enter
}
// remove `show` class will be never passed.
I expecect that Dropdown could be opened and closed manually (through JS) - then requrements to have toggles is excessive (the same is true for dropdown class requirement - you use it to find dropdown-menu but if dropdown-menu by itself is an jquery element - it still should work )
Bug reports must include a live demo of the problem. Per our contributing guidelines, please create a reduced test case via CodePen or JS Bin and report back with your link, Bootstrap version, and specific browser and OS details.
Johan, first of all I would like to know does it sounds as a bug: that data-toggle="dropdown" is required.
May be this is "by design" and you do not bother about Dropdown menus dropdown-menu created, opened and closed from user's code without dropdown and data-toggle="dropdown" .
dropdown-menu is not enough to use Dropdown plugin from JavaScript, there should be corresponded dropdown and data-toggle="dropdown" on the form (even if you do not really need them since you are.. using JavaScript .. means DOM events to toggle menu);
We recommend use popper.js directly for such scenarious.
BTW this doesn't work either
<ul class="dropdown-menu dropdown" data-toggle='dropdown' >
<li class="dropdown-item">..</li>
<li class="dropdown-item">..</li>
</ul>
$('.dropdown-menu').dropdown({
placement: 'bottom-start',
flip: false,
reference: this.filterInput
}); // will not work because "initialization" is stolen by bs on document handler which is attached to dropdown.
Same. To be clear, I think OP is looking for a way to have a manually controlled dropdown without the automatic data-api triggering it to open.
In my case I'd like to display a dropdown under search input group, but I don't want the user toggling it open and closed while the search is still executing. I'll find a workaround, but it would be simpler if there was an alternative markup that would stop the built-in event handler. (I'll probably go adding the "disabled" class to the input group, which I see the dropdown looks for. Not sure where that rabbit trail leads, though.)
I ran into this issue trying to using a text input as a dropdown toggle. I want to allow the user to click around in and edit the input's text value without triggering the menu. Adding and removing the disabled class did solve some of the related problems, i.e. clicking in the input no longer triggers the menu. However, adding the disabled class prevents some of the dropdown keyboard interactions.
Activity
Johann-S commentedon Apr 30, 2018
Bug reports must include a live demo of the problem. Per our contributing guidelines, please create a reduced test case via CodePen or JS Bin and report back with your link, Bootstrap version, and specific browser and OS details.
rpokrovskij commentedon Apr 30, 2018
Johan, first of all I would like to know does it sounds as a bug: that
data-toggle="dropdown"is required.May be this is "by design" and you do not bother about Dropdown menus dropdown-menu created, opened and closed from user's code without
dropdownanddata-toggle="dropdown".Johann-S commentedon Apr 30, 2018
Yep
data-toggle="dropdown"is a requirement for us, it's the only way to be sure there is only one dropdown open (see: https://github.com/twbs/bootstrap/blob/v4-dev/js/src/dropdown.js#L336)rpokrovskij commentedon Apr 30, 2018
Then this just should be added to documentation:
BTW this doesn't work either
P.S. I have tried to use bs dropdown as autosuggestion popup.
https://dashboardcode.github.io/BsMultiSelect/
XhmikosR commentedon Oct 12, 2018
@Johann-S: is this still an issue (docs update)?
Johann-S commentedon Oct 21, 2018
yep we should update our docs
chamnap commentedon Jan 13, 2019
It happens to me the same as @rpokrovskij.
When adding
data-toggle='dropdown', the initialization is already done by the data api on the document level, https://github.com/twbs/bootstrap/blob/v4-dev/js/src/dropdown.js#L515. Therefore, we cannot manually initialized it.Without
data-toggle='dropdown', the dropdown doesn't close itself when clicking outside.Any workarounds for now?
mkleehammer commentedon Jun 6, 2019
Same. To be clear, I think OP is looking for a way to have a manually controlled dropdown without the automatic data-api triggering it to open.
In my case I'd like to display a dropdown under search input group, but I don't want the user toggling it open and closed while the search is still executing. I'll find a workaround, but it would be simpler if there was an alternative markup that would stop the built-in event handler. (I'll probably go adding the "disabled" class to the input group, which I see the dropdown looks for. Not sure where that rabbit trail leads, though.)
nteetor commentedon Nov 12, 2019
I ran into this issue trying to using a text input as a dropdown toggle. I want to allow the user to click around in and edit the input's text value without triggering the menu. Adding and removing the
disabledclass did solve some of the related problems, i.e. clicking in the input no longer triggers the menu. However, adding thedisabledclass prevents some of the dropdown keyboard interactions.mdo commentedon Sep 19, 2020
Docs state the requirement about the data attribute in a (hopefully obvious) callout. https://getbootstrap.com/docs/4.5/components/dropdowns/#via-javascript
f3d0fee
Beyond that, I don't think there are any planned changes to how dropdowns work here unless @Johann-S wants to revisit things.