0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-30 22:52:24 +01:00

Fix bug where backdrop calls method on null if it is already removed from the body (#34014)

Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com>
This commit is contained in:
Ryan Weaver 2021-05-21 18:16:05 -04:00 committed by GitHub
parent d64466a248
commit a2b5901efc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -116,7 +116,11 @@ class Backdrop {
EventHandler.off(this._element, EVENT_MOUSEDOWN) EventHandler.off(this._element, EVENT_MOUSEDOWN)
this._getElement().parentNode.removeChild(this._element) const { parentNode } = this._getElement()
if (parentNode) {
parentNode.removeChild(this._element)
}
this._isAppended = false this._isAppended = false
} }

View File

@ -129,6 +129,25 @@ describe('Backdrop', () => {
}) })
}) })
it('should not error if the backdrop no longer has a parent', done => {
const instance = new Backdrop({
isVisible: true,
isAnimated: true
})
const getElements = () => document.querySelectorAll(CLASS_BACKDROP)
instance.show(() => {
instance.hide(() => {
expect(getElements().length).toEqual(0)
// replace the fixture, which was just wiped out
fixtureEl = getFixture()
done()
})
document.body.innerHTML = 'changed'
})
})
describe('click callback', () => { describe('click callback', () => {
it('it should execute callback on click', done => { it('it should execute callback on click', done => {
const spy = jasmine.createSpy('spy') const spy = jasmine.createSpy('spy')