From 03288542850a1dd6e39abd23871725b7a46ea43d Mon Sep 17 00:00:00 2001 From: Chris Haynes Date: Thu, 23 Jul 2020 22:12:05 +0100 Subject: [PATCH] Fixes #135 - uses the composedPath() array to find the closest matching elements the event was triggered on (#136) composedPath() is preferred over closest() since it pierces shadow DOM boundaries --- src/components/dropdown/dropdown.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/dropdown/dropdown.tsx b/src/components/dropdown/dropdown.tsx index 32e2b599..289b38b5 100644 --- a/src/components/dropdown/dropdown.tsx +++ b/src/components/dropdown/dropdown.tsx @@ -217,10 +217,9 @@ export class Dropdown { } handleDocumentMouseDown(event: MouseEvent) { - const target = event.target as HTMLElement; - // Close when clicking outside of the close element - if (target.closest(this.containingElement.tagName.toLowerCase()) !== this.containingElement) { + const path = event.composedPath() as Array; + if (!path.includes(this.containingElement)) { this.hide(); return; }