Skip to content

Commit

Permalink
[Fix #17371][V4] Deactivating dropdown links in nav tab (#17642)
Browse files Browse the repository at this point in the history
* Fix bug with dropdown tab links not deactivating when other tab or dropdown link is clicked

* Revise bug fix for more stability
  • Loading branch information
matt-hernandez authored and mdo committed Nov 25, 2016
1 parent 3593ee8 commit b1b1f30
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const Tab = (($) => {
if (active) {
$(active).removeClass(ClassName.ACTIVE)

let dropdownChild = $(active).find(
let dropdownChild = $(active.parentNode).find(
Selector.DROPDOWN_ACTIVE_CHILD
)[0]

Expand Down
32 changes: 32 additions & 0 deletions js/tests/unit/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,36 @@ $(function () {
assert.strictEqual($tabs.find('a:not(.active)').attr('aria-expanded'), 'false', 'after second show event, hidden tab has aria-expanded = false')
})

QUnit.test('selected tab should deactivate previous selected tab', 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>'
+ '</ul>'
var $tabs = $(tabsHTML).appendTo('#qunit-fixture')

$tabs.find('li:last a').trigger('click')
assert.notOk($tabs.find('li:first a').hasClass('active'))
assert.ok($tabs.find('li:last a').hasClass('active'))
})

QUnit.test('selected tab should deactivate previous selected link in dropdown', function (assert) {
assert.expect(3)
var tabsHTML = '<ul class="nav nav-tabs">'
+ '<li class="nav-item"><a class="nav-link" 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 active" data-toggle="dropdown" href="#">Dropdown</a>'
+ '<div class="dropdown-menu">'
+ '<a class="dropdown-item active" href="#dropdown1" id="dropdown1-tab" data-toggle="tab">@fat</a>'
+ '<a class="dropdown-item" href="#dropdown2" id="dropdown2-tab" data-toggle="tab">@mdo</a>'
+ '</div>'
+ '</li>'
+ '</ul>'
var $tabs = $(tabsHTML).appendTo('#qunit-fixture')

$tabs.find('li:first > a').trigger('click')
assert.ok($tabs.find('li:first a').hasClass('active'))
assert.notOk($tabs.find('li:last > a').hasClass('active'))
assert.notOk($tabs.find('li:last > .dropdown-menu > a:first').hasClass('active'))
})
})

0 comments on commit b1b1f30

Please sign in to comment.