From 68db42c9f86fcdfcca0cc049cbde30d0d73df88a Mon Sep 17 00:00:00 2001 From: vsn4ik Date: Tue, 23 Jan 2018 02:03:00 +0300 Subject: [PATCH] Fix skip element disabled via attribute when using keyboard navigation --- js/src/dropdown.js | 2 +- js/tests/unit/dropdown.js | 40 ++++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 2f69298540..64d6b37176 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -57,7 +57,7 @@ const Dropdown = (($) => { FORM_CHILD : '.dropdown form', MENU : '.dropdown-menu', NAVBAR_NAV : '.navbar-nav', - VISIBLE_ITEMS : '.dropdown-menu .dropdown-item:not(.disabled)' + VISIBLE_ITEMS : '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)' } const AttachmentMap = { diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 3040e81b41..0e3d370413 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -544,15 +544,15 @@ $(function () { $dropdown.trigger('click') }) - QUnit.test('should skip disabled element when using keyboard navigation', function (assert) { - assert.expect(2) + QUnit.test('should focus next/previous element when using keyboard navigation', function (assert) { + assert.expect(4) var done = assert.async() var dropdownHTML = '
' + '' + '
' @@ -568,24 +568,32 @@ $(function () { $dropdown.trigger($.Event('keydown', { which: 40 })) - $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('.disabled'), '.disabled is not 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') }) - 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 = '
' + '' + '
' @@ -601,17 +609,11 @@ $(function () { $dropdown.trigger($.Event('keydown', { which: 40 })) - assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused') - - $(document.activeElement).trigger($.Event('keydown', { + assert.ok($(document.activeElement).is($('#item1')), '#item1 is focused') + $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($('#item1')), '#item1 is still focused') done() }) $dropdown.trigger('click') -- 2.47.2