From 8893045bf145a051fb37ff47375d193bb14f7e72 Mon Sep 17 00:00:00 2001 From: bolte-17 <3034257+bolte-17@users.noreply.github.com> Date: Thu, 27 Oct 2022 09:28:35 -0400 Subject: [PATCH] Avoid null dereference when removing event listeners in Dropdown (#958) --- src/components/dropdown/dropdown.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/dropdown/dropdown.ts b/src/components/dropdown/dropdown.ts index aa5c2a40..17ff2bd2 100644 --- a/src/components/dropdown/dropdown.ts +++ b/src/components/dropdown/dropdown.ts @@ -346,8 +346,10 @@ export default class SlDropdown extends ShoelaceElement { } removeOpenListeners() { - this.panel.removeEventListener('sl-activate', this.handleMenuItemActivate); - this.panel.removeEventListener('sl-select', this.handlePanelSelect); + if (this.panel) { + this.panel.removeEventListener('sl-activate', this.handleMenuItemActivate); + this.panel.removeEventListener('sl-select', this.handlePanelSelect); + } document.removeEventListener('keydown', this.handleDocumentKeyDown); document.removeEventListener('mousedown', this.handleDocumentMouseDown); }