Skip to content
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
10 changes: 5 additions & 5 deletions js/src/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Tab = (($) => {
A : 'a',
LI : 'li',
DROPDOWN : '.dropdown',
UL : 'ul:not(.dropdown-menu)',
LIST : 'ul:not(.dropdown-menu), ol:not(.dropdown-menu)',
FADE_CHILD : '> .nav-item .fade, > .fade',
ACTIVE : '.active',
ACTIVE_CHILD : '> .nav-item > .active, > .active',
Expand Down Expand Up @@ -85,11 +85,11 @@ const Tab = (($) => {

let target
let previous
let ulElement = $(this._element).closest(Selector.UL)[0]
let listElement = $(this._element).closest(Selector.LIST)[0]
let selector = Util.getSelectorFromElement(this._element)

if (ulElement) {
previous = $.makeArray($(ulElement).find(Selector.ACTIVE))
if (listElement) {
previous = $.makeArray($(listElement).find(Selector.ACTIVE))
previous = previous[previous.length - 1]
}

Expand Down Expand Up @@ -118,7 +118,7 @@ const Tab = (($) => {

this._activate(
this._element,
ulElement
listElement
)

let complete = () => {
Expand Down
16 changes: 16 additions & 0 deletions js/tests/unit/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ $(function () {
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
})

QUnit.test('should activate element by tab id in ordered list', function (assert) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'QUnit' is not defined no-undef
Unexpected function expression prefer-arrow-callback

assert.expect(2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No magic number: 2 no-magic-numbers

var pillsHTML = '<ol class="pills">'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected var, use let or const instead no-var

+ '<li><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>'
+ '</ol>'

$('<ol><li id="home"/><li id="profile"/></ol>').appendTo('#qunit-fixture')

$(pillsHTML).find('li:last a').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')

$(pillsHTML).find('li:first a').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
})

QUnit.test('should not fire shown when show is prevented', function (assert) {
assert.expect(1)
var done = assert.async()
Expand Down