Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown: support .dropdown-item wrapped in <li> tags #33649

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion js/src/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions js/tests/unit/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
'<ul class="nav nav-tabs">',
' <li class="nav-item"><a class="nav-link active" href="#home" data-toggle="tab">Home</a></li>',
' <li class="nav-item"><a class="nav-link" href="#profile" data-toggle="tab">Profile</a></li>',
' <li class="nav-item dropdown">',
' <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">Dropdown</a>',
' <ul class="dropdown-menu">',
' <li><a class="dropdown-item" href="#dropdown1" id="dropdown1-tab" data-toggle="tab">@fat</a></li>',
' <li><a class="dropdown-item" href="#dropdown2" id="dropdown2-tab" data-toggle="tab">@mdo</a></li>',
' </ul>',
' </li>',
'</ul>'
].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').hasClass('active'))
cpsievert marked this conversation as resolved.
Show resolved Hide resolved
})

QUnit.test('Nested tabs', function (assert) {
assert.expect(2)
var done = assert.async()
Expand Down