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

Fix active class toggling of tabs within dropdown #37151

Merged
merged 2 commits into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions js/src/tab.js
Expand Up @@ -38,7 +38,6 @@ const CLASS_DROPDOWN = 'dropdown'

const SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle'
const SELECTOR_DROPDOWN_MENU = '.dropdown-menu'
const SELECTOR_DROPDOWN_ITEM = '.dropdown-item'
const NOT_SELECTOR_DROPDOWN_TOGGLE = ':not(.dropdown-toggle)'

const SELECTOR_TAB_PANEL = '.list-group, .nav, [role="tablist"]'
Expand Down Expand Up @@ -231,7 +230,6 @@ class Tab extends BaseComponent {

toggle(SELECTOR_DROPDOWN_TOGGLE, CLASS_NAME_ACTIVE)
toggle(SELECTOR_DROPDOWN_MENU, CLASS_NAME_SHOW)
toggle(SELECTOR_DROPDOWN_ITEM, CLASS_NAME_ACTIVE)
outerElem.setAttribute('aria-expanded', open)
}

Expand Down
7 changes: 4 additions & 3 deletions js/tests/unit/tab.spec.js
Expand Up @@ -840,10 +840,11 @@ describe('Tab', () => {
'</ul>'
].join('')

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

firstDropItem.click()
expect(firstDropItem).toHaveClass('active')
dropItems[1].click()
expect(dropItems[0]).not.toHaveClass('active')
expect(dropItems[1]).toHaveClass('active')
expect(fixtureEl.querySelector('.nav-link')).not.toHaveClass('active')
})

Expand Down