bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Fix active class toggling of tabs within dropdown

Open cpsievert opened this issue 2 years ago • 1 comments

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

cpsievert avatar Sep 14 '22 15:09 cpsievert

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 avatar Sep 21 '22 08:09 GeoSot

@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

cpsievert avatar Sep 21 '22 19:09 cpsievert

I 've checked it and you are right. Thanks, @cpsievert 👍

GeoSot avatar Sep 21 '22 23:09 GeoSot