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 #17371][V4] Deactivating dropdown links in nav tab #17642

Merged
merged 2 commits into from
Nov 25, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,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 @@ -213,4 +213,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'))
})
})