Skip to content

Commit fb3f070

Browse files
committed
refactor: simplify esc guard to improve determinism
1 parent b59d9b0 commit fb3f070

1 file changed

Lines changed: 1 addition & 8 deletions

File tree

src/Preview/index.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,21 +337,13 @@ const Preview: React.FC<PreviewProps> = props => {
337337
const { keyCode, key } = event;
338338

339339
if (keyCode === KeyCode.ESC || key === 'Escape') {
340-
if (escClosingRef.current) {
341-
return;
342-
}
343-
344340
escClosingRef.current = true;
345341
openRef.current = false;
346342
event.preventDefault();
347343
if (keyCode === KeyCode.ESC) {
348344
event.stopPropagation();
349345
}
350346
onClose?.();
351-
352-
setTimeout(() => {
353-
escClosingRef.current = false;
354-
}, 0);
355347
return;
356348
}
357349

@@ -387,6 +379,7 @@ const Preview: React.FC<PreviewProps> = props => {
387379
const onVisibleChanged = (nextVisible: boolean) => {
388380
if (!nextVisible) {
389381
setLockScroll(false);
382+
escClosingRef.current = false;
390383
}
391384
afterOpenChange?.(nextVisible);
392385
};

0 commit comments

Comments
 (0)