@@ -19,31 +19,29 @@ export function useModal() {
1919    const  {  animationDuration,  transitionDuration }  =  getComputedStyle ( modal ) ; 
2020
2121    if  ( animationDuration  !==  '0s' )  { 
22-       modal . addEventListener ( 
23-         'animationend' , 
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-           } 
31-         } , 
32-         {  once : true  } , 
33-       ) ; 
22+       const  handler  =  ( e : AnimationEvent )  =>  { 
23+         if  ( e . target  ===  modal )  { 
24+           delete  modal . dataset . closing ; 
25+           modal . classList . remove ( 'modal-closing' ) ; 
26+           enableBodyScroll ( modal ) ; 
27+           modal . close ( ) ; 
28+           modal . removeEventListener ( 'animationend' ,  handler ) ; 
29+         } 
30+       } ; 
31+ 
32+       modal . addEventListener ( 'animationend' ,  handler ) ; 
3433    }  else  if  ( transitionDuration  !==  '0s' )  { 
35-       modal . addEventListener ( 
36-         'transitionend' , 
37-         ( e )  =>  { 
38-           if  ( e . target  ===  modal )  { 
39-             delete  modal . dataset . closing ; 
40-             modal . classList . remove ( 'modal-closing' ) ; 
41-             enableBodyScroll ( modal ) ; 
42-             modal . close ( ) ; 
43-           } 
44-         } , 
45-         {  once : true  } , 
46-       ) ; 
34+       const  handler  =  ( e : TransitionEvent )  =>  { 
35+         if  ( e . target  ===  modal )  { 
36+           delete  modal . dataset . closing ; 
37+           modal . classList . remove ( 'modal-closing' ) ; 
38+           enableBodyScroll ( modal ) ; 
39+           modal . close ( ) ; 
40+           modal . removeEventListener ( 'transitionend' ,  handler ) ; 
41+         } 
42+       } ; 
43+ 
44+       modal . addEventListener ( 'transitionend' ,  handler ) ; 
4745    }  else  if  ( animationDuration  ===  '0s'  &&  transitionDuration  ===  '0s' )  { 
4846      delete  modal . dataset . closing ; 
4947      modal . classList . remove ( 'modal-closing' ) ; 
0 commit comments