Skip to content

Commit

Permalink
Merge pull request #273 from FrameMuse/modal-window-not-closing-via-c…
Browse files Browse the repository at this point in the history
…ontroller

Fix modal window closing
  • Loading branch information
FrameMuse committed May 28, 2024
2 parents 5bb05e9 + a08a601 commit 66a85e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 7 additions & 1 deletion src/ModalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ModalController<Config extends Partial<ModalControllerConfig> = ModalContr
const modalWindow = new ModalWindow(component, { ...this.config?.defaultParams, ...modalParams as MODAL_WINDOW_PARAMS_EXPLANATION<P> })
// 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.
Expand Down Expand Up @@ -155,6 +155,12 @@ class ModalController<Config extends Partial<ModalControllerConfig> = 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

Expand Down

0 comments on commit 66a85e3

Please sign in to comment.