File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -327,14 +327,21 @@ const Preview: React.FC<PreviewProps> = props => {
327327 }
328328 } ;
329329
330+ const escClosingRef = useRef ( false ) ;
331+
330332 // >>>>> Effect: Keyboard
331333 const onKeyDown = useEvent ( ( event : KeyboardEvent ) => {
332334 if ( open ) {
333335 const { keyCode, key } = event ;
334336
335337 if ( keyCode === KeyCode . ESC || key === 'Escape' ) {
338+ escClosingRef . current = true ;
336339 event . preventDefault ( ) ;
337340 onClose ?.( ) ;
341+
342+ Promise . resolve ( ) . then ( ( ) => {
343+ escClosingRef . current = false ;
344+ } ) ;
338345 return ;
339346 }
340347
@@ -382,6 +389,12 @@ const Preview: React.FC<PreviewProps> = props => {
382389 }
383390 } , [ open ] ) ;
384391
392+ const onEsc : PortalProps [ 'onEsc' ] = ( { top } ) => {
393+ if ( top && ! escClosingRef . current ) {
394+ onClose ?.( ) ;
395+ }
396+ } ;
397+
385398 // ========================== Render ==========================
386399 const bodyStyle : React . CSSProperties = {
387400 ...styles . body ,
@@ -396,6 +409,7 @@ const Preview: React.FC<PreviewProps> = props => {
396409 autoDestroy = { false }
397410 getContainer = { getContainer }
398411 autoLock = { lockScroll }
412+ onEsc = { onEsc }
399413 >
400414 < CSSMotion
401415 motionName = { motionName }
You can’t perform that action at this time.
0 commit comments