diff --git a/package.json b/package.json index 5a6e0f4..0fd8c05 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "type": "module", "name": "react-modal-global", - "version": "2.3.4", + "version": "2.3.6", "description": "Uncontrollable Global React Modal", - "main": "dist/index.ts", + "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ "dist", diff --git a/src/ModalController.ts b/src/ModalController.ts index 257d49d..4fe7382 100644 --- a/src/ModalController.ts +++ b/src/ModalController.ts @@ -98,7 +98,7 @@ class ModalController = ModalContr const modalWindow = new ModalWindow(component, { ...this.config?.defaultParams, ...modalParams as MODAL_WINDOW_PARAMS_EXPLANATION

}) // Using `on` instead of `then` since `then` will only be executed on the next event loop iteration. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Event_loop. - modalWindow.on("close", () => this.close(modalWindow)) + modalWindow.on("close", () => this.remove(modalWindow)) // Skip adding to queue if the window is already the last modal. @@ -155,6 +155,12 @@ class ModalController = ModalContr * Closes modal by its instance. */ public close(modalWindow: ModalWindowAny): void { + if (!this.windows.has(modalWindow)) return + + modalWindow.close() + } + + private remove(modalWindow: ModalWindowAny): void { if (this.windows.size === 0) return if (!this.windows.has(modalWindow)) return