Skip to content

Commit ad02d5d

Browse files
yoyo837claude
andcommitted
fix: use capture phase and stopImmediatePropagation for ESC key handling
- Register keydown listener in capture phase (true) so Preview handler fires before any bubble-phase listeners (e.g. parent Dialog) - Replace stopPropagation with stopImmediatePropagation to also block other capture-phase listeners registered after this one Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b3c0dc6 commit ad02d5d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Preview/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ const Preview: React.FC<PreviewProps> = props => {
334334

335335
if (keyCode === KeyCode.ESC || key === 'Escape') {
336336
event.preventDefault();
337-
event.stopPropagation();
337+
event.stopImmediatePropagation();
338338
onClose?.();
339339
return;
340340
}
@@ -351,10 +351,10 @@ const Preview: React.FC<PreviewProps> = props => {
351351

352352
useEffect(() => {
353353
if (open) {
354-
window.addEventListener('keydown', onKeyDown);
354+
window.addEventListener('keydown', onKeyDown, true);
355355

356356
return () => {
357-
window.removeEventListener('keydown', onKeyDown);
357+
window.removeEventListener('keydown', onKeyDown, true);
358358
};
359359
}
360360
}, [open]);

0 commit comments

Comments
 (0)