From ba10b63c9da3c0fab5611e8001e490af527b8c7a Mon Sep 17 00:00:00 2001 From: Johann-S Date: Fri, 13 Apr 2018 11:52:12 +0200 Subject: [PATCH] fix issue related to Object.keys and Dropdown issue --- js/src/collapse.js | 2 +- js/src/modal.js | 2 +- js/src/scrollspy.js | 2 +- js/src/tooltip.js | 2 +- js/tests/unit/dropdown.js | 70 +++++++++++++++++++-------------------- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/js/src/collapse.js b/js/src/collapse.js index c3b3599ecc..e22cf0b7ab 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -331,7 +331,7 @@ const Collapse = (($) => { const _config = { ...Default, ...$this.data(), - ...typeof config === 'object' && config + ...typeof config === 'object' && config ? config : {} } if (!data && _config.toggle && /show|hide/.test(config)) { diff --git a/js/src/modal.js b/js/src/modal.js index 1df4152666..e3de68b8fe 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -500,7 +500,7 @@ const Modal = (($) => { const _config = { ...Default, ...$(this).data(), - ...typeof config === 'object' && config + ...typeof config === 'object' && config ? config : {} } if (!data) { diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 1c46940f53..d8cf69473b 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -165,7 +165,7 @@ const ScrollSpy = (($) => { _getConfig(config) { config = { ...Default, - ...config + ...typeof config === 'object' && config ? config : {} } if (typeof config.target !== 'string') { diff --git a/js/src/tooltip.js b/js/src/tooltip.js index f751ee3c94..59c26897c9 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -611,7 +611,7 @@ const Tooltip = (($) => { config = { ...this.constructor.Default, ...$(this.element).data(), - ...config + ...typeof config === 'object' && config ? config : {} } if (typeof config.delay === 'number') { diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 726655e9cc..f87c65bea0 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -544,6 +544,41 @@ $(function () { $dropdown.trigger('click') }) + QUnit.test('should skip disabled element when using keyboard navigation', function (assert) { + assert.expect(3) + var done = assert.async() + var dropdownHTML = '
' + + '' + + '
' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + $dropdown.trigger($.Event('keydown', { + which: 40 + })) + $dropdown.trigger($.Event('keydown', { + which: 40 + })) + 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 focus next/previous element when using keyboard navigation', function (assert) { assert.expect(4) var done = assert.async() @@ -584,41 +619,6 @@ $(function () { $dropdown.trigger('click') }) - QUnit.test('should skip disabled element when using keyboard navigation', function (assert) { - assert.expect(3) - var done = assert.async() - var dropdownHTML = '
' + - '' + - '
' - var $dropdown = $(dropdownHTML) - .appendTo('#qunit-fixture') - .find('[data-toggle="dropdown"]') - .bootstrapDropdown() - - $dropdown - .parent('.dropdown') - .on('shown.bs.dropdown', function () { - assert.ok(true, 'shown was fired') - $dropdown.trigger($.Event('keydown', { - which: 40 - })) - assert.ok($(document.activeElement).is($('#item1')), '#item1 is focused') - $dropdown.trigger($.Event('keydown', { - which: 40 - })) - assert.ok($(document.activeElement).is($('#item1')), '#item1 is still focused') - done() - }) - $dropdown.trigger('click') - }) - QUnit.test('should not close the dropdown if the user clicks on a text field', function (assert) { assert.expect(2) var done = assert.async()