Add dialog manager for one-at-a-time filters

This commit is contained in:
Andy Smith
2025-11-06 16:46:50 -06:00
parent 626bc1b985
commit 7aba1db93a
2 changed files with 25 additions and 1 deletions
@@ -0,0 +1,24 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
this.element.addEventListener("dialog:show", this.handleDialogShow.bind(this))
}
disconnect() {
this.element.removeEventListener("dialog:show", this.handleDialogShow.bind(this))
}
handleDialogShow(event) {
this.#dialogControllers.forEach(dialogController => {
if (dialogController !== event.target) {
const dialog = dialogController.querySelector("dialog")
dialog.removeAttribute("open")
}
})
}
get #dialogControllers() {
return this.element.querySelectorAll('[data-controller~="dialog"]')
}
}