mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-17 09:52:29 +01:00
Fix triggering of {shown,hidden}.bs.dropdown events so relatedTarget gets set properly
Fixes #16828 Closes #16865
This commit is contained in:
parent
9433924732
commit
ef1ce9ac0b
@ -51,7 +51,7 @@
|
||||
if (e.isDefaultPrevented()) return
|
||||
|
||||
$this.attr('aria-expanded', 'false')
|
||||
$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
|
||||
$parent.removeClass('open').trigger($.Event('hidden.bs.dropdown', relatedTarget))
|
||||
})
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@
|
||||
|
||||
$parent
|
||||
.toggleClass('open')
|
||||
.trigger('shown.bs.dropdown', relatedTarget)
|
||||
.trigger($.Event('shown.bs.dropdown', relatedTarget))
|
||||
}
|
||||
|
||||
return false
|
||||
|
@ -286,6 +286,38 @@ $(function () {
|
||||
$(document.body).trigger('click')
|
||||
})
|
||||
|
||||
QUnit.test('should fire shown and hidden event with a relatedTarget', function (assert) {
|
||||
assert.expect(2)
|
||||
var dropdownHTML = '<ul class="tabs">'
|
||||
+ '<li class="dropdown">'
|
||||
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
|
||||
+ '<ul class="dropdown-menu">'
|
||||
+ '<li><a href="#">Secondary link</a></li>'
|
||||
+ '<li><a href="#">Something else here</a></li>'
|
||||
+ '<li class="divider"/>'
|
||||
+ '<li><a href="#">Another link</a></li>'
|
||||
+ '</ul>'
|
||||
+ '</li>'
|
||||
+ '</ul>'
|
||||
var $dropdown = $(dropdownHTML)
|
||||
.appendTo('#qunit-fixture')
|
||||
.find('[data-toggle="dropdown"]')
|
||||
.bootstrapDropdown()
|
||||
var done = assert.async()
|
||||
|
||||
$dropdown.parent('.dropdown')
|
||||
.on('hidden.bs.dropdown', function (e) {
|
||||
assert.strictEqual(e.relatedTarget, $dropdown[0])
|
||||
done()
|
||||
})
|
||||
.on('shown.bs.dropdown', function (e) {
|
||||
assert.strictEqual(e.relatedTarget, $dropdown[0])
|
||||
$(document.body).trigger('click')
|
||||
})
|
||||
|
||||
$dropdown.trigger('click')
|
||||
})
|
||||
|
||||
QUnit.test('should ignore keyboard events within <input>s and <textarea>s', function (assert) {
|
||||
assert.expect(3)
|
||||
var done = assert.async()
|
||||
|
Loading…
x
Reference in New Issue
Block a user