1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-20 13:49:39 +02:00
Maybe/app/javascript/controllers/dropdown_controller.js

24 lines
543 B
JavaScript
Raw Normal View History

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");
}
hideMenu = () => {
2024-02-02 09:05:04 -06:00
this.menuTarget.classList.add("hidden");
}
connect() {
document.addEventListener("click", this.hideMenu);
2024-02-02 09:05:04 -06:00
}
disconnect() {
document.removeEventListener("click", this.hideMenu);
2024-02-02 09:05:04 -06:00
}
}