diff --git a/web/static/numerus.js b/web/static/numerus.js index 9916f5e..4bf11e9 100644 --- a/web/static/numerus.js +++ b/web/static/numerus.js @@ -345,12 +345,14 @@ class Tags extends HTMLDivElement { this.search.addEventListener('keydown', this.onSearchKeydownHandler); this.onFocusOutHandler = (e) => { if (this.contains(e.target)) return; + if (!e.target.isConnected) return; if (this.search.value && this.search.value.trim() !== '') { this.createTag(); } this.dispatchEvent(new CustomEvent("numerus-tags-out", {bubbles: true})) }; window.addEventListener('focusin', this.onFocusOutHandler); + document.addEventListener('click', this.onFocusOutHandler); this.rebuild(); } @@ -359,6 +361,7 @@ class Tags extends HTMLDivElement { disconnectedCallback() { if (this.initialized) { this.removeTags(); + document.removeEventListener('click', this.onFocusOutHandler); window.removeEventListener('focusin', this.onFocusOutHandler); this.onFocusOutHandler = null; this.search.removeEventListener('keydown', this.onSearchKeydownHandler);