0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +01:00
dropdown - destroy old popper.js references
This commit is contained in:
Johann-S 2019-08-22 21:23:42 +02:00 committed by XhmikosR
parent 41b8ce278b
commit bab999701c
2 changed files with 49 additions and 1 deletions

View File

@ -436,6 +436,10 @@ class Dropdown {
toggles[i].setAttribute('aria-expanded', 'false')
if (context._popper) {
context._popper.destroy()
}
$(dropdownMenu).removeClass(ClassName.SHOW)
$(parent)
.removeClass(ClassName.SHOW)

View File

@ -799,7 +799,7 @@ $(function () {
.parent('.dropdown')
.on('shown.bs.dropdown', function () {
// Forcibly focus first item
$item.focus()
$item[0].focus()
assert.ok($(document.activeElement)[0] === $item[0], 'menu item initial focus set')
// Key escape
@ -1506,4 +1506,48 @@ $(function () {
assert.strictEqual(popperConfig.placement, 'left')
})
QUnit.test('should destroy old popper references on toggle', function (assert) {
assert.expect(3)
var done = assert.async()
var fixtureHtml = [
'<div class="first dropdown">',
' <button href="#" class="firstBtn btn" data-toggle="dropdown" aria-expanded="false">Dropdown</button>',
' <div class="dropdown-menu">',
' <a class="dropdown-item" href="#">Secondary link</a>',
' </div>',
'</div>',
'<div class="second dropdown">',
' <button href="#" class="secondBtn btn" data-toggle="dropdown" aria-expanded="false">Dropdown</button>',
' <div class="dropdown-menu">',
' <a class="dropdown-item" href="#">Secondary link</a>',
' </div>',
'</div>'
].join('')
$(fixtureHtml).appendTo('#qunit-fixture')
var $btnDropdown1 = $('.firstBtn').bootstrapDropdown()
var $btnDropdown2 = $('.secondBtn').bootstrapDropdown()
var $firstDropdownEl = $('.first')
var $secondDropdownEl = $('.second')
var dropdown1 = $btnDropdown1.data('bs.dropdown')
var dropdown2 = $btnDropdown2.data('bs.dropdown')
var spyPopper
$firstDropdownEl.one('shown.bs.dropdown', function () {
assert.strictEqual($firstDropdownEl.hasClass('show'), true)
spyPopper = sinon.spy(dropdown1._popper, 'destroy')
dropdown2.toggle()
})
$secondDropdownEl.one('shown.bs.dropdown', function () {
assert.strictEqual($secondDropdownEl.hasClass('show'), true)
assert.ok(spyPopper.called)
done()
})
dropdown1.toggle()
})
})