Skip to content

Commit 21d89e9

Browse files
authored
Update Modal.js
Allows us to set `data-close="modal-dialog-id"` on the trigger element to close a modal, before opening another modal.
1 parent 5677e11 commit 21d89e9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docs/js/Modal.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818
event.preventDefault();
1919
const modal = document.getElementById(event.currentTarget.dataset.target);
2020
if (!modal) return;
21-
modal && (modal.open ? closeModal(modal) : openModal(modal));
21+
if(event.currentTarget.dataset.close) {
22+
const modalClose = document.getElementById(event.currentTarget.dataset.close);
23+
if(modalClose){
24+
closeModal(modalClose);
25+
setTimeout(() => modal && (modal.open ? closeModal(modal) : openModal(modal)), animationDuration);
26+
}
27+
} else {
28+
modal && (modal.open ? closeModal(modal) : openModal(modal));
29+
}
2230
};
2331

2432
// Open modal

0 commit comments

Comments
 (0)