2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-05-15 11:59:39 +03:00

Add missing things in hide method of dropdown

This commit is contained in:
Julien Déramond
2022-06-08 21:56:18 +02:00
parent 6fd203060b
commit 7ebb190a2d
2 changed files with 13 additions and 7 deletions
+8 -2
View File
@@ -202,11 +202,18 @@ class Dropdown {
return
}
// If this is a touch-enabled device we remove the extra
// empty mouseover listeners we added for iOS support
if ('ontouchstart' in document.documentElement) {
$(document.body).children().off('mouseover', null, $.noop)
}
if (this._popper) {
this._popper.destroy()
}
$(this._menu).toggleClass(CLASS_NAME_SHOW)
this._element.setAttribute('aria-expanded', false)
$(parent)
.toggleClass(CLASS_NAME_SHOW)
.trigger($.Event(EVENT_HIDDEN, relatedTarget))
@@ -404,13 +411,12 @@ class Dropdown {
$(document.body).children().off('mouseover', null, $.noop)
}
toggles[i].setAttribute('aria-expanded', 'false')
if (context._popper) {
context._popper.destroy()
}
$(dropdownMenu).removeClass(CLASS_NAME_SHOW)
toggles[i].setAttribute('aria-expanded', 'false')
$(parent)
.removeClass(CLASS_NAME_SHOW)
.trigger($.Event(EVENT_HIDDEN, relatedTarget))
+5 -5
View File
@@ -1585,12 +1585,12 @@ $(function () {
})
QUnit.test('should hide a dropdown and destroy popper', function (assert) {
assert.expect(1)
assert.expect(2)
var done = assert.async()
var fixtureHtml = [
'<div class="dropdown">',
' <button href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>',
' <button href="#" class="btn dropdown-toggle" data-toggle="dropdown" aria-expanded="true">Dropdown</button>',
' <div class="dropdown-menu">',
' <a class="dropdown-item" href="#">Secondary link</a>',
' </div>',
@@ -1600,9 +1600,8 @@ $(function () {
$(fixtureHtml).appendTo('#qunit-fixture')
var $dropdownEl = $('.dropdown')
var dropdown = $('[data-toggle="dropdown"]')
.bootstrapDropdown()
.data('bs.dropdown')
var $btnDropdown = $('[data-toggle="dropdown"]').bootstrapDropdown()
var dropdown = $btnDropdown.data('bs.dropdown')
var spyPopper
$dropdownEl.one('shown.bs.dropdown', function () {
@@ -1612,6 +1611,7 @@ $(function () {
$dropdownEl.one('hidden.bs.dropdown', function () {
assert.true(spyPopper.called)
assert.strictEqual($btnDropdown.attr('aria-expanded'), 'false', 'aria-expanded is set to string "false" on hide')
done()
})