From 4b5eb3ca5166f959815c626af5587b9192336ef5 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Tue, 27 Apr 2021 23:02:22 -0500 Subject: [PATCH] Backport #33634 (#33649) Dropdown: support `.dropdown-item` wrapped in `
  • ` tags --- js/src/tab.js | 7 ++++++- js/tests/unit/tab.js | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/js/src/tab.js b/js/src/tab.js index e9a6f555fe..bcbb5c5ea2 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -187,7 +187,12 @@ class Tab { element.classList.add(CLASS_NAME_SHOW) } - if (element.parentNode && $(element.parentNode).hasClass(CLASS_NAME_DROPDOWN_MENU)) { + let parent = element.parentNode + if (parent && parent.nodeName === 'LI') { + parent = parent.parentNode + } + + if (parent && $(parent).hasClass(CLASS_NAME_DROPDOWN_MENU)) { const dropdownElement = $(element).closest(SELECTOR_DROPDOWN)[0] if (dropdownElement) { diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js index a0c4ddf155..9c9b286f04 100644 --- a/js/tests/unit/tab.js +++ b/js/tests/unit/tab.js @@ -345,6 +345,28 @@ $(function () { assert.notOk($tabs.find('li:last-child .dropdown-menu a:first-child').hasClass('active')) }) + QUnit.test('should support li > .dropdown-item', function (assert) { + assert.expect(2) + var tabsHTML = [ + '' + ].join('') + var $tabs = $(tabsHTML).appendTo('#qunit-fixture') + + $tabs.find('.dropdown-item').trigger('click') + assert.ok($tabs.find('.dropdown-item').hasClass('active')) + assert.notOk($tabs.find('.nav-link:not(.dropdown-toggle)').hasClass('active')) + }) + QUnit.test('Nested tabs', function (assert) { assert.expect(2) var done = assert.async()