mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
26 lines
485 B
JavaScript
26 lines
485 B
JavaScript
import { Controller } from "stimulus";
|
|
|
|
export default class extends Controller {
|
|
static targets = ["content"];
|
|
|
|
connect() {
|
|
super.connect();
|
|
window.addEventListener("click", this.#hideIfClickedOutside);
|
|
}
|
|
|
|
toggle() {
|
|
this.contentTarget.classList.toggle("show");
|
|
}
|
|
|
|
#hideIfClickedOutside = (event) => {
|
|
if (this.element.contains(event.target)) {
|
|
return;
|
|
}
|
|
this.#hide();
|
|
};
|
|
|
|
#hide() {
|
|
this.contentTarget.classList.remove("show");
|
|
}
|
|
}
|