bootstrap
bootstrap copied to clipboard
Fix active class toggling of tabs within dropdown
Closes #36947 (a regression introduced by https://github.com/twbs/bootstrap/pull/33079, cc @GeoSot)
As the codepen in #36947 demonstrates, when clicking on the 2nd tab in a dropdown, all the tabs within the dropdown are marked with an active class. This happens because, the current logic in _toggleDropdown()
toggles the active class on the first tab within the dropdown when it shouldn't be
Looking back the commits history, it seems that Tab was handling only the removal of active class https://github.com/twbs/bootstrap/blob/63d38b19740eac25b8603dc9a9ae11e1df4667f7/js/src/tab.js#L116-L120
So if we want to bring back the exact old behavior, I think it would be better to rename the const SELECTOR_DROPDOWN_ITEM
, to
const SELECTOR_DROPDOWN_ITEM_ACTIVE = '.dropdown-item.active'
and use it, instead of remove the handling
@cpsievert what do you think about this?
@GeoSot I don't think that's necessary since, in the new implementation, by the time we reach _toggleDropdown()
, the .active
class will already be added/removed from the tab via
https://github.com/twbs/bootstrap/blob/37e2e7e1249b0e514d6d07e3ee1bc01dbdc42c8d/js/src/tab.js#L103-L108
and
https://github.com/twbs/bootstrap/blob/37e2e7e1249b0e514d6d07e3ee1bc01dbdc42c8d/js/src/tab.js#L129-L134
I 've checked it and you are right. Thanks, @cpsievert 👍