Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/itchy-bobcats-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@qwik-ui/headless': patch
---

fix: modal closing with a custom animation now always works, even if there are animated elements inside the modal
46 changes: 22 additions & 24 deletions packages/kit-headless/src/components/modal/use-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,29 @@ export function useModal() {
const { animationDuration, transitionDuration } = getComputedStyle(modal);

if (animationDuration !== '0s') {
modal.addEventListener(
'animationend',
(e) => {
if (e.target === modal) {
delete modal.dataset.closing;
modal.classList.remove('modal-closing');
enableBodyScroll(modal);
modal.close();
}
},
{ once: true },
);
const handler = (e: AnimationEvent) => {
if (e.target === modal) {
delete modal.dataset.closing;
modal.classList.remove('modal-closing');
enableBodyScroll(modal);
modal.close();
modal.removeEventListener('animationend', handler);
}
};

modal.addEventListener('animationend', handler);
} else if (transitionDuration !== '0s') {
modal.addEventListener(
'transitionend',
(e) => {
if (e.target === modal) {
delete modal.dataset.closing;
modal.classList.remove('modal-closing');
enableBodyScroll(modal);
modal.close();
}
},
{ once: true },
);
const handler = (e: TransitionEvent) => {
if (e.target === modal) {
delete modal.dataset.closing;
modal.classList.remove('modal-closing');
enableBodyScroll(modal);
modal.close();
modal.removeEventListener('transitionend', handler);
}
};

modal.addEventListener('transitionend', handler);
} else if (animationDuration === '0s' && transitionDuration === '0s') {
delete modal.dataset.closing;
modal.classList.remove('modal-closing');
Expand Down
Loading