mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-01 13:24:25 +01:00
This commit is contained in:
parent
1b575c27cd
commit
8cc9defbc0
@ -452,9 +452,6 @@ class Dropdown {
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
if (this.disabled || $(this).hasClass(CLASS_NAME_DISABLED)) {
|
||||
return
|
||||
}
|
||||
@ -466,6 +463,9 @@ class Dropdown {
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
if (!isActive || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) {
|
||||
if (event.which === ESCAPE_KEYCODE) {
|
||||
const toggle = parent.querySelector(SELECTOR_DATA_TOGGLE)
|
||||
|
@ -1020,6 +1020,70 @@ $(function () {
|
||||
$textarea.trigger('click')
|
||||
})
|
||||
|
||||
QUnit.test('should not stop key event propagation when dropdown is disabled', function (assert) {
|
||||
assert.expect(1)
|
||||
var done = assert.async()
|
||||
|
||||
var dropdownHTML = '<div class="tabs">' +
|
||||
'<div class="dropdown">' +
|
||||
'<a href="#" class="dropdown-toggle" id="toggle" data-toggle="dropdown" disabled>Dropdown</a>' +
|
||||
'<div class="dropdown-menu">' +
|
||||
'<a class="dropdown-item" id="item" href="#">Menu item</a>' +
|
||||
'</div>' +
|
||||
'</div>'
|
||||
|
||||
var $dropdown = $(dropdownHTML)
|
||||
.appendTo('#qunit-fixture')
|
||||
.find('[data-toggle="dropdown"]')
|
||||
.bootstrapDropdown()
|
||||
|
||||
var $body = $('body')
|
||||
|
||||
$(document).on('keydown', function () {
|
||||
$body.addClass('event-handled')
|
||||
})
|
||||
|
||||
// Key escape
|
||||
$dropdown.trigger('focus').trigger($.Event('keydown', {
|
||||
which: 27
|
||||
}))
|
||||
|
||||
assert.ok($body.hasClass('event-handled'), 'ESC key event was propagated')
|
||||
done()
|
||||
})
|
||||
|
||||
QUnit.test('should not stop ESC key event propagation when dropdown is not active', function (assert) {
|
||||
assert.expect(1)
|
||||
var done = assert.async()
|
||||
|
||||
var dropdownHTML = '<div class="tabs">' +
|
||||
'<div class="dropdown">' +
|
||||
'<a href="#" class="dropdown-toggle" id="toggle" data-toggle="dropdown">Dropdown</a>' +
|
||||
'<div class="dropdown-menu">' +
|
||||
'<a class="dropdown-item" id="item" href="#">Menu item</a>' +
|
||||
'</div>' +
|
||||
'</div>'
|
||||
|
||||
var $dropdown = $(dropdownHTML)
|
||||
.appendTo('#qunit-fixture')
|
||||
.find('[data-toggle="dropdown"]')
|
||||
.bootstrapDropdown()
|
||||
|
||||
var $body = $('body')
|
||||
|
||||
$(document).on('keydown', function () {
|
||||
$body.addClass('event-handled')
|
||||
})
|
||||
|
||||
// Key escape
|
||||
$dropdown.trigger('focus').trigger($.Event('keydown', {
|
||||
which: 27
|
||||
}))
|
||||
|
||||
assert.ok($body.hasClass('event-handled'), 'ESC key event was propagated')
|
||||
done()
|
||||
})
|
||||
|
||||
QUnit.test('should not use Popper.js if display set to static', function (assert) {
|
||||
assert.expect(1)
|
||||
var dropdownHTML =
|
||||
|
Loading…
Reference in New Issue
Block a user