mirror of
https://github.com/we-promise/sure.git
synced 2026-04-08 06:44:52 +00:00
Add inline category selection (#541)
* Implement inline category selection * Add turbo frame to refresh updated transaction * Improve styles * Fix category assignment * Reorganize code * Revert event propagation * Remove unused frames * Make only the transaction name clickable * Add custom scrollbar class
This commit is contained in:
@@ -4,20 +4,32 @@ import { Controller } from "@hotwired/stimulus"
|
||||
export default class extends Controller {
|
||||
static targets = ["menu"]
|
||||
|
||||
toggleMenu(event) {
|
||||
event.stopPropagation(); // Prevent event from closing the menu immediately
|
||||
this.menuTarget.classList.toggle("hidden");
|
||||
toggleMenu = (e) => {
|
||||
e.stopPropagation(); // Prevent event from closing the menu immediately
|
||||
this.menuTarget.classList.contains("hidden") ? this.showMenu() : this.hideMenu();
|
||||
}
|
||||
|
||||
showMenu = () => {
|
||||
document.addEventListener("click", this.onDocumentClick);
|
||||
this.menuTarget.classList.remove("hidden");
|
||||
}
|
||||
|
||||
hideMenu = () => {
|
||||
document.removeEventListener("click", this.onDocumentClick);
|
||||
this.menuTarget.classList.add("hidden");
|
||||
}
|
||||
|
||||
connect() {
|
||||
document.addEventListener("click", this.hideMenu);
|
||||
disconnect = () => {
|
||||
this.hideMenu();
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
document.removeEventListener("click", this.hideMenu);
|
||||
onDocumentClick = (e) => {
|
||||
if (this.menuTarget.contains(e.target)) {
|
||||
// user has clicked inside of the dropdown
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
|
||||
this.hideMenu();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user