Skip to content

Commit 709f3d0

Browse files
authored
Merge pull request #752 from maiieul/fix-headless-modal--event-bubbling
fix(headless modal): prevent bubbling of animationend and transitionend event listeners
2 parents 35f122b + 19be3b5 commit 709f3d0

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/kit-headless/src/components/modal/use-modal.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,27 @@ export function useModal() {
2121
if (animationDuration !== '0s') {
2222
modal.addEventListener(
2323
'animationend',
24-
() => {
25-
delete modal.dataset.closing;
26-
modal.classList.remove('modal-closing');
27-
enableBodyScroll(modal);
28-
modal.close();
24+
(e) => {
25+
if (e.target === modal) {
26+
delete modal.dataset.closing;
27+
modal.classList.remove('modal-closing');
28+
enableBodyScroll(modal);
29+
modal.close();
30+
}
2931
},
3032
{ once: true },
3133
);
3234
}
3335
if (transitionDuration !== '0s') {
3436
modal.addEventListener(
3537
'transitionend',
36-
() => {
37-
delete modal.dataset.closing;
38-
modal.classList.remove('modal-closing');
39-
enableBodyScroll(modal);
40-
modal.close();
38+
(e) => {
39+
if (e.target === modal) {
40+
delete modal.dataset.closing;
41+
modal.classList.remove('modal-closing');
42+
enableBodyScroll(modal);
43+
modal.close();
44+
}
4145
},
4246
{ once: true },
4347
);

0 commit comments

Comments
 (0)