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
2 changes: 1 addition & 1 deletion js/src/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ const Collapse = (($) => {
const _config = {
...Default,
...$this.data(),
...typeof config === 'object' && config
...typeof config === 'object' && config ? config : {}
Copy link
Copy Markdown
Contributor

@vsn4ik vsn4ik Apr 13, 2018

Choose a reason for hiding this comment

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

Why not

typeof config === 'object' ? config : {}

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yep that can be enough thanks 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Finally I won't make this change because it'll decrease our code coverage

}

if (!data && _config.toggle && /show|hide/.test(config)) {
Expand Down
2 changes: 1 addition & 1 deletion js/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ const Modal = (($) => {
const _config = {
...Default,
...$(this).data(),
...typeof config === 'object' && config
...typeof config === 'object' && config ? config : {}
}

if (!data) {
Expand Down
2 changes: 1 addition & 1 deletion js/src/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const ScrollSpy = (($) => {
_getConfig(config) {
config = {
...Default,
...config
...typeof config === 'object' && config ? config : {}
}

if (typeof config.target !== 'string') {
Expand Down
2 changes: 1 addition & 1 deletion js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ const Tooltip = (($) => {
config = {
...this.constructor.Default,
...$(this.element).data(),
...config
...typeof config === 'object' && config ? config : {}
}

if (typeof config.delay === 'number') {
Expand Down
42 changes: 21 additions & 21 deletions js/tests/unit/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,16 @@ $(function () {
$dropdown.trigger('click')
})

QUnit.test('should focus next/previous element when using keyboard navigation', function (assert) {
assert.expect(4)
QUnit.test('should skip disabled element when using keyboard navigation', function (assert) {
assert.expect(3)
var done = assert.async()
var dropdownHTML = '<div class="tabs">' +
'<div class="dropdown">' +
'<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' +
'<div class="dropdown-menu">' +
'<a id="item1" class="dropdown-item" href="#">A link</a>' +
'<a id="item2" class="dropdown-item" href="#">Another link</a>' +
'<a class="dropdown-item disabled" href="#">Disabled link</a>' +
'<button class="dropdown-item" type="button" disabled>Disabled button</button>' +
'<a id="item1" class="dropdown-item" href="#">Another link</a>' +
'</div>' +
'</div>' +
'</div>'
Expand All @@ -568,32 +569,25 @@ $(function () {
$dropdown.trigger($.Event('keydown', {
which: 40
}))
assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused')

$(document.activeElement).trigger($.Event('keydown', {
$dropdown.trigger($.Event('keydown', {
which: 40
}))
assert.ok($(document.activeElement).is($('#item2')), 'item2 is focused')

$(document.activeElement).trigger($.Event('keydown', {
which: 38
}))
assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused')
assert.ok(!$(document.activeElement).is('.disabled'), '.disabled is not focused')
assert.ok(!$(document.activeElement).is(':disabled'), ':disabled is not focused')
done()
})
$dropdown.trigger('click')
})

QUnit.test('should skip disabled element when using keyboard navigation', function (assert) {
assert.expect(3)
QUnit.test('should focus next/previous element when using keyboard navigation', function (assert) {
assert.expect(4)
var done = assert.async()
var dropdownHTML = '<div class="tabs">' +
'<div class="dropdown">' +
'<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' +
'<div class="dropdown-menu">' +
'<a class="dropdown-item disabled" href="#">Disabled link</a>' +
'<button class="dropdown-item" type="button" disabled>Disabled button</button>' +
'<a id="item1" class="dropdown-item" href="#">Another link</a>' +
'<a id="item1" class="dropdown-item" href="#">A link</a>' +
'<a id="item2" class="dropdown-item" href="#">Another link</a>' +
'</div>' +
'</div>' +
'</div>'
Expand All @@ -609,11 +603,17 @@ $(function () {
$dropdown.trigger($.Event('keydown', {
which: 40
}))
assert.ok($(document.activeElement).is($('#item1')), '#item1 is focused')
$dropdown.trigger($.Event('keydown', {
assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused')

$(document.activeElement).trigger($.Event('keydown', {
which: 40
}))
assert.ok($(document.activeElement).is($('#item1')), '#item1 is still focused')
assert.ok($(document.activeElement).is($('#item2')), 'item2 is focused')

$(document.activeElement).trigger($.Event('keydown', {
which: 38
}))
assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused')
done()
})
$dropdown.trigger('click')
Expand Down