1
- import React , { useEffect , useState , ReactNode , useContext } from 'react' ;
1
+ import React , { useEffect , useState , ReactNode , useContext , useRef } from 'react' ;
2
2
import { createGlobalStyle } from 'styled-components' ;
3
3
import { WidthProps } from 'styled-system' ;
4
4
import { useIsEscKeyPressed } from '../../utils/hooks/useIsEscKeyPressed' ;
@@ -56,12 +56,13 @@ const ANIMATION_DURATION = Math.max(DIMMING_ANIMATION_DURATION, CARD_ANIMATION_D
56
56
const Modal : React . FC < ModalProps > = ( { children, onClose, dismissible, ...rest } : ModalProps ) => {
57
57
const [ visible , setVisible ] = useState ( true ) ;
58
58
const isEscKeyPressed = useIsEscKeyPressed ( ) ;
59
+ const closeTimeout = useRef ( null ) ;
59
60
60
61
const handleClose : DismissFunc = ( ) => {
61
62
setVisible ( false ) ;
62
63
63
64
if ( onClose ) {
64
- setTimeout ( ( ) => onClose ( ) , ANIMATION_DURATION ) ;
65
+ closeTimeout . current = setTimeout ( ( ) => onClose ( ) , ANIMATION_DURATION ) ;
65
66
}
66
67
} ;
67
68
@@ -77,6 +78,13 @@ const Modal: React.FC<ModalProps> = ({ children, onClose, dismissible, ...rest }
77
78
}
78
79
} , [ dismissible , isEscKeyPressed ] ) ;
79
80
81
+ useEffect (
82
+ ( ) => ( ) => {
83
+ if ( closeTimeout . current ) clearTimeout ( closeTimeout . current ) ;
84
+ } ,
85
+ [ ]
86
+ ) ;
87
+
80
88
const renderChildren = ( ) => {
81
89
if ( typeof children === 'function' ) {
82
90
return children ( handleClose ) ;
0 commit comments