mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-01 13:24:25 +01:00
Fix skip element disabled via attribute when using keyboard navigation
This commit is contained in:
parent
2cd700313d
commit
68db42c9f8
@ -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 = {
|
||||
|
@ -544,39 +544,6 @@ $(function () {
|
||||
$dropdown.trigger('click')
|
||||
})
|
||||
|
||||
QUnit.test('should skip disabled element when using keyboard navigation', function (assert) {
|
||||
assert.expect(2)
|
||||
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>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>'
|
||||
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')
|
||||
done()
|
||||
})
|
||||
$dropdown.trigger('click')
|
||||
})
|
||||
|
||||
QUnit.test('should focus next/previous element when using keyboard navigation', function (assert) {
|
||||
assert.expect(4)
|
||||
var done = assert.async()
|
||||
@ -617,6 +584,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 = '<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>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>'
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user