@@ -66,7 +66,6 @@ const Dialog = props => {
66
66
67
67
const [ firstVisible , setFirst ] = useState ( pvisible || false ) ;
68
68
const [ visible , setVisible ] = useState ( pvisible ) ;
69
- const [ isAnimationEnd , markAnimationEnd ] = useState ( false ) ;
70
69
const getContainer =
71
70
typeof popupContainer === 'string'
72
71
? ( ) => document . getElementById ( popupContainer )
@@ -81,6 +80,13 @@ const Dialog = props => {
81
80
const [ uuid ] = useState ( guid ( ) ) ;
82
81
const { setVisibleOverlayToParent, ...otherContext } = useContext ( OverlayContext ) ;
83
82
const childIDMap = useRef ( new Map ( ) ) ;
83
+ const isAnimationEnd = useRef ( false ) ;
84
+ const [ , forceUpdate ] = useState ( ) ;
85
+
86
+ const markAnimationEnd = state => {
87
+ isAnimationEnd . current = state ;
88
+ forceUpdate ( { } ) ;
89
+ } ;
84
90
85
91
let canCloseByEsc = false ;
86
92
let canCloseByMask = false ;
@@ -160,11 +166,35 @@ const Dialog = props => {
160
166
}
161
167
} , [ container ] ) ;
162
168
169
+ const handleExited = ( ) => {
170
+ if ( ! isAnimationEnd . current ) {
171
+ markAnimationEnd ( true ) ;
172
+ dom . setStyle ( wrapperRef . current , 'display' , 'none' ) ;
173
+ scrollLocker . unlock ( document . body , locker . current ) ;
174
+
175
+ if ( autoFocus && lastFocus . current ) {
176
+ try {
177
+ lastFocus . current . focus ( ) ;
178
+ } finally {
179
+ // ignore ...
180
+ }
181
+ lastFocus . current = null ;
182
+ }
183
+ afterClose ( ) ;
184
+ }
185
+ } ;
186
+
187
+ useEffect ( ( ) => {
188
+ return ( ) => {
189
+ handleExited ( ) ;
190
+ } ;
191
+ } , [ ] ) ;
192
+
163
193
if ( firstVisible === false || ! container ) {
164
194
return null ;
165
195
}
166
196
167
- if ( ! visible && ! cache && isAnimationEnd ) {
197
+ if ( ! visible && ! cache && isAnimationEnd . current ) {
168
198
return null ;
169
199
}
170
200
@@ -206,22 +236,6 @@ const Dialog = props => {
206
236
setVisibleOverlayToParent ( uuid , wrapperRef . current ) ;
207
237
} ;
208
238
209
- const handleExited = ( ) => {
210
- markAnimationEnd ( true ) ;
211
- dom . setStyle ( wrapperRef . current , 'display' , 'none' ) ;
212
- scrollLocker . unlock ( document . body , locker . current ) ;
213
-
214
- if ( autoFocus && lastFocus . current ) {
215
- try {
216
- lastFocus . current . focus ( ) ;
217
- } finally {
218
- // ignore ...
219
- }
220
- lastFocus . current = null ;
221
- }
222
- afterClose ( ) ;
223
- } ;
224
-
225
239
const wrapperCls = classNames ( {
226
240
[ `${ prefix } overlay-wrapper` ] : true ,
227
241
opened : visible ,
0 commit comments