Dispatch "closing" event when closing modal

This allow for any other controller to trigger an action when the modal
is closed
This commit is contained in:
Gaetan Craig-Riou
2025-02-17 16:50:49 +11:00
parent 4a63efd342
commit 9d59f87b30

View File

@@ -12,8 +12,10 @@ export const useOpenAndCloseAsAModal = (controller) => {
}.bind(controller),
close: function (_event, remove = false) {
// displatch closing event so other controller can trigger action when the modal closes
this.dispatch("closing");
// Only execute close if the current modal is open
if (!this.modalTarget.classList.contains('in')) return;
if (!this.modalTarget.classList.contains("in")) return;
this.modalTarget.classList.remove("in");
this.backgroundTarget.classList.remove("in");
@@ -22,7 +24,9 @@ export const useOpenAndCloseAsAModal = (controller) => {
setTimeout(() => {
this.backgroundTarget.style.display = "none";
this.modalTarget.style.display = "none";
if (remove) { this.element.remove() }
if (remove) {
this.element.remove();
}
}, 200);
}.bind(controller),