From 8cafe32ce7650f10624631c427cad6b46163f62e Mon Sep 17 00:00:00 2001 From: f Date: Sat, 18 May 2024 18:48:49 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20poder=20ocultar=20con=20un=20evento=20t?= =?UTF-8?q?ambi=C3=A9n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/controllers/modal_controller.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/javascript/controllers/modal_controller.js b/app/javascript/controllers/modal_controller.js index 011c1254..20154f79 100644 --- a/app/javascript/controllers/modal_controller.js +++ b/app/javascript/controllers/modal_controller.js @@ -6,13 +6,16 @@ export default class extends Controller { // TODO: Stimulus >1 connect() { this.showEvent = this.show.bind(this); + this.hideEvent = this.hide.bind(this); window.addEventListener("modal:show", this.showEvent); + window.addEventListener("modal:hide", this.hideEvent); } // TODO: Stimulus >1 disconnect() { window.removeEventListener("modal:show", this.showEvent); + window.removeEventListener("modal:hide", this.hideEvent); } /* @@ -41,6 +44,9 @@ export default class extends Controller { hide(event = undefined) { event?.preventDefault(); + const modalId = event?.detail?.id; + + if (modalId && this.element.id !== modalId) return; this.backdropTarget.classList.remove("show"); this.modalTarget.classList.remove("show");