From e3fe6ba0a91dda38a818c27c3ac77f7b1e236d11 Mon Sep 17 00:00:00 2001 From: jasoncruz98 Date: Tue, 19 Sep 2023 19:48:42 +0800 Subject: [PATCH 1/2] added check to make sure there are no existing backdrops before new ones are created --- src/components/drawer/index.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/drawer/index.ts b/src/components/drawer/index.ts index 55f71c62d..8f6600607 100644 --- a/src/components/drawer/index.ts +++ b/src/components/drawer/index.ts @@ -158,21 +158,25 @@ class Drawer implements DrawerInterface { _createBackdrop() { if (!this._visible) { - const backdropEl = document.createElement('div'); - backdropEl.setAttribute('drawer-backdrop', ''); - backdropEl.classList.add( - ...this._options.backdropClasses.split(' ') - ); - document.querySelector('body').append(backdropEl); - backdropEl.addEventListener('click', () => { - this.hide(); - }); + const existingBackdrop = document.querySelector('[drawer-backdrop]'); + if (!existingBackdrop) { + const backdropEl = document.createElement('div'); + backdropEl.setAttribute('drawer-backdrop', ''); + backdropEl.classList.add(...this._options.backdropClasses.split(' ')); + document.querySelector('body')!.append(backdropEl); + backdropEl.addEventListener('click', () => { + this.hide(); + }); + } } } - _destroyBackdropEl() { + _destroyBackdropEl(): void { if (this._visible) { - document.querySelector('[drawer-backdrop]').remove(); + const backdropElements = document.querySelectorAll('[drawer-backdrop]'); + backdropElements.forEach(element => { + element.remove(); + }); } } From 6ac114bb859c2bfbde90f537684c085db038588c Mon Sep 17 00:00:00 2001 From: jasoncruz98 Date: Tue, 19 Sep 2023 19:49:31 +0800 Subject: [PATCH 2/2] removed redundant change to _destroyBackdropEl --- src/components/drawer/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/drawer/index.ts b/src/components/drawer/index.ts index 8f6600607..ad31b3053 100644 --- a/src/components/drawer/index.ts +++ b/src/components/drawer/index.ts @@ -171,12 +171,9 @@ class Drawer implements DrawerInterface { } } - _destroyBackdropEl(): void { + _destroyBackdropEl() { if (this._visible) { - const backdropElements = document.querySelectorAll('[drawer-backdrop]'); - backdropElements.forEach(element => { - element.remove(); - }); + document.querySelector('[drawer-backdrop]').remove(); } }