Skip to content

Commit 68db42c

Browse files
vsn4ikJohann-S
authored andcommitted
Fix skip element disabled via attribute when using keyboard navigation
1 parent 2cd7003 commit 68db42c

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

js/src/dropdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const Dropdown = (($) => {
5757
FORM_CHILD : '.dropdown form',
5858
MENU : '.dropdown-menu',
5959
NAVBAR_NAV : '.navbar-nav',
60-
VISIBLE_ITEMS : '.dropdown-menu .dropdown-item:not(.disabled)'
60+
VISIBLE_ITEMS : '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)'
6161
}
6262

6363
const AttachmentMap = {

js/tests/unit/dropdown.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,15 @@ $(function () {
544544
$dropdown.trigger('click')
545545
})
546546

547-
QUnit.test('should skip disabled element when using keyboard navigation', function (assert) {
548-
assert.expect(2)
547+
QUnit.test('should focus next/previous element when using keyboard navigation', function (assert) {
548+
assert.expect(4)
549549
var done = assert.async()
550550
var dropdownHTML = '<div class="tabs">' +
551551
'<div class="dropdown">' +
552552
'<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' +
553553
'<div class="dropdown-menu">' +
554-
'<a class="dropdown-item disabled" href="#">Disabled link</a>' +
555-
'<a class="dropdown-item" href="#">Another link</a>' +
554+
'<a id="item1" class="dropdown-item" href="#">A link</a>' +
555+
'<a id="item2" class="dropdown-item" href="#">Another link</a>' +
556556
'</div>' +
557557
'</div>' +
558558
'</div>'
@@ -568,24 +568,32 @@ $(function () {
568568
$dropdown.trigger($.Event('keydown', {
569569
which: 40
570570
}))
571-
$dropdown.trigger($.Event('keydown', {
571+
assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused')
572+
573+
$(document.activeElement).trigger($.Event('keydown', {
572574
which: 40
573575
}))
574-
assert.ok(!$(document.activeElement).is('.disabled'), '.disabled is not focused')
576+
assert.ok($(document.activeElement).is($('#item2')), 'item2 is focused')
577+
578+
$(document.activeElement).trigger($.Event('keydown', {
579+
which: 38
580+
}))
581+
assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused')
575582
done()
576583
})
577584
$dropdown.trigger('click')
578585
})
579586

580-
QUnit.test('should focus next/previous element when using keyboard navigation', function (assert) {
581-
assert.expect(4)
587+
QUnit.test('should skip disabled element when using keyboard navigation', function (assert) {
588+
assert.expect(3)
582589
var done = assert.async()
583590
var dropdownHTML = '<div class="tabs">' +
584591
'<div class="dropdown">' +
585592
'<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' +
586593
'<div class="dropdown-menu">' +
587-
'<a id="item1" class="dropdown-item" href="#">A link</a>' +
588-
'<a id="item2" class="dropdown-item" href="#">Another link</a>' +
594+
'<a class="dropdown-item disabled" href="#">Disabled link</a>' +
595+
'<button class="dropdown-item" type="button" disabled>Disabled button</button>' +
596+
'<a id="item1" class="dropdown-item" href="#">Another link</a>' +
589597
'</div>' +
590598
'</div>' +
591599
'</div>'
@@ -601,17 +609,11 @@ $(function () {
601609
$dropdown.trigger($.Event('keydown', {
602610
which: 40
603611
}))
604-
assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused')
605-
606-
$(document.activeElement).trigger($.Event('keydown', {
612+
assert.ok($(document.activeElement).is($('#item1')), '#item1 is focused')
613+
$dropdown.trigger($.Event('keydown', {
607614
which: 40
608615
}))
609-
assert.ok($(document.activeElement).is($('#item2')), 'item2 is focused')
610-
611-
$(document.activeElement).trigger($.Event('keydown', {
612-
which: 38
613-
}))
614-
assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused')
616+
assert.ok($(document.activeElement).is($('#item1')), '#item1 is still focused')
615617
done()
616618
})
617619
$dropdown.trigger('click')

0 commit comments

Comments
 (0)