some more functions

This commit is contained in:
Simon Martens
2025-06-04 23:01:35 +02:00
parent 3a6dcc0e3d
commit b8e43efc2a
6 changed files with 349 additions and 164 deletions

View File

@@ -18,6 +18,8 @@ export class DivManager extends HTMLElement {
constructor() {
super();
this.#reset();
// INFO: we do this to avoid binding issues with the event listener
this.boundHandleClickOutside = this.handleClickOutside.bind(this);
}
#reset() {
@@ -88,8 +90,17 @@ export class DivManager extends HTMLElement {
if (this._menu.classList.contains(TAILWIND_HIDDEN_CLASS)) {
this._menu.classList.remove(TAILWIND_HIDDEN_CLASS);
document.addEventListener("click", this.handleClickOutside);
} else {
this._menu.classList.add(TAILWIND_HIDDEN_CLASS);
document.removeEventListener("click", this.handleClickOutside);
}
}
handleClickOutside(event) {
if (!this._menu) return;
if (!this._menu.contains(event.target) && !this._button.contains(event.target)) {
this._menu.classList.add(TAILWIND_HIDDEN_CLASS);
}
}