Dropdowns now close when clicking outside of them

This commit is contained in:
Pax1601
2023-05-04 09:54:26 +02:00
parent e3b88d4e35
commit 7ecfc5afef
3 changed files with 16 additions and 39 deletions

View File

@@ -19,17 +19,18 @@ export class Dropdown {
this.setOptions(options);
}
this.#value.addEventListener( "click", ev => {
this.#element.classList.toggle( "is-open" );
this.#value.addEventListener("click", (ev) => {
this.#element.classList.toggle("is-open");
this.#clip();
});
this.#options.classList.add( "ol-scrollable" );
document.addEventListener("click", (ev) => {
if (!(this.#value.contains(ev.target as Node) || this.#options.contains(ev.target as Node) || this.#element.contains(ev.target as Node))) {
this.#element.classList.remove("is-open");
}
});
// Commented out since it is a bit frustrating, particularly when the dropdown opens towards the top and not to the bottom
//this.#element.addEventListener("mouseleave", ev => {
// this.#close();
//});
this.#options.classList.add( "ol-scrollable" );
}
setOptions(optionsList: string[])