From bbec85905138e55b67a38811b87ae66d7658e071 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Fri, 7 Aug 2026 23:05:55 -0400 Subject: [PATCH] Modals: emit lt:modalclose so openers can react to any dismissal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A modal can be dismissed four ways: the ✕ button, a Cancel button, a backdrop click, or Escape. The last two are handled globally in base.js, so code that wires only the buttons never learns the modal went away — leaving optimistic UI in place, and leaving dynamically-inserted overlays in the DOM (where the next open inserts a duplicate id that shadows the live one). closeModal now dispatches a bubbling lt:modalclose CustomEvent on the overlay. Existing button handlers keep working; openers that care can listen for it. --- base.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/base.js b/base.js index cd20236..c4d76ec 100644 --- a/base.js +++ b/base.js @@ -241,6 +241,11 @@ trigger.focus(); } } + // Announce the close so whoever opened the modal can undo optimistic UI or + // clean up a dynamically-inserted overlay. A modal can be dismissed four + // ways — the ✕ button, a Cancel button, a backdrop click, and Escape — and + // the last two are handled globally here, so button-only listeners miss them. + el.dispatchEvent(new CustomEvent('lt:modalclose', { bubbles: true })); } function closeAllModals() {