Skip to content

Commit

Permalink
Update Modal.js
Browse files Browse the repository at this point in the history
Allows us to set `data-close="modal-dialog-id"` on the trigger element to close a modal, before opening another modal.
  • Loading branch information
Yohn authored Jan 7, 2025
1 parent 5677e11 commit 21d89e9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs/js/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
event.preventDefault();
const modal = document.getElementById(event.currentTarget.dataset.target);
if (!modal) return;
modal && (modal.open ? closeModal(modal) : openModal(modal));
if(event.currentTarget.dataset.close) {
const modalClose = document.getElementById(event.currentTarget.dataset.close);
if(modalClose){
closeModal(modalClose);
setTimeout(() => modal && (modal.open ? closeModal(modal) : openModal(modal)), animationDuration);
}
} else {
modal && (modal.open ? closeModal(modal) : openModal(modal));
}
};

// Open modal
Expand Down

0 comments on commit 21d89e9

Please sign in to comment.