Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown. Skip element disabled via attribute when using keyboard navigation #25403

Merged
merged 1 commit into from
Mar 26, 2018
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/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
40 changes: 21 additions & 19 deletions js/tests/unit/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<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>' +
'<a 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 @@ -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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed order of tests

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 @@ -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')
Expand Down