2024-02-02 09:05:04 -06:00
|
|
|
import { Controller } from "@hotwired/stimulus"
|
|
|
|
|
|
|
|
// Connects to data-controller="dropdown"
|
|
|
|
export default class extends Controller {
|
|
|
|
static targets = ["menu"]
|
|
|
|
|
|
|
|
toggleMenu(event) {
|
|
|
|
event.stopPropagation(); // Prevent event from closing the menu immediately
|
|
|
|
this.menuTarget.classList.toggle("hidden");
|
|
|
|
}
|
|
|
|
|
2024-02-08 14:37:36 -05:00
|
|
|
hideMenu = () => {
|
2024-02-02 09:05:04 -06:00
|
|
|
this.menuTarget.classList.add("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
connect() {
|
2024-02-08 14:37:36 -05:00
|
|
|
document.addEventListener("click", this.hideMenu);
|
2024-02-02 09:05:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
disconnect() {
|
2024-02-08 14:37:36 -05:00
|
|
|
document.removeEventListener("click", this.hideMenu);
|
2024-02-02 09:05:04 -06:00
|
|
|
}
|
2024-02-08 14:37:36 -05:00
|
|
|
}
|