Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
Next Next commit
Close #33625: support .dropdown-item wrapped in <li> tags
  • Loading branch information
cpsievert committed Apr 15, 2021
commit d976313ff54c9afb033d56794e019a79d8179323
7 changes: 6 additions & 1 deletion js/src/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ class Tab extends BaseComponent {
element.classList.add(CLASS_NAME_SHOW)
}

if (element.parentNode && element.parentNode.classList.contains(CLASS_NAME_DROPDOWN_MENU)) {
let parent = element.parentNode
if (parent && parent.nodeName === 'LI') {
parent = parent.parentNode
}

if (parent && parent.classList.contains(CLASS_NAME_DROPDOWN_MENU)) {
const dropdownElement = element.closest(SELECTOR_DROPDOWN)

if (dropdownElement) {
Expand Down
22 changes: 22 additions & 0 deletions js/tests/unit/tab.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,28 @@ describe('Tab', () => {
expect(fixtureEl.querySelector('#nav2 .dropdown-item').classList.contains('active')).toEqual(false)
})

it('should support li > .dropdown-item', () => {
fixtureEl.innerHTML = [
'<ul class="nav nav-tabs">',
' <li class="nav-item"><a class="nav-link active" href="#home" data-bs-toggle="tab">Home</a></li>',
' <li class="nav-item"><a class="nav-link" href="#profile" data-bs-toggle="tab">Profile</a></li>',
' <li class="nav-item dropdown">',
' <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#">Dropdown</a>',
' <div class="dropdown-menu">',
' <li><a class="dropdown-item" href="#dropdown1" id="dropdown1-tab" data-bs-toggle="tab">@fat</a></li>',
' <li><a class="dropdown-item" href="#dropdown2" id="dropdown2-tab" data-bs-toggle="tab">@mdo</a></li>',
' </div>',
' </li>',
'</ul>'
].join('')

const firstDropItem = fixtureEl.querySelector('.dropdown-item')

firstDropItem.click()
expect(firstDropItem.classList.contains('active')).toEqual(true)
expect(fixtureEl.querySelector('.nav-link').classList.contains('active')).toEqual(false)
})

it('should handle nested tabs', done => {
fixtureEl.innerHTML = [
'<nav class="nav nav-tabs" role="tablist">',
Expand Down