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
pull/146/head
Chris Haynes 2020-07-23 22:12:05 +01:00 zatwierdzone przez GitHub
rodzic 81816fba56
commit 0328854285
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 2 dodań i 3 usunięć

Wyświetl plik

@ -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<EventTarget>;
if (!path.includes(this.containingElement)) {
this.hide();
return;
}