fix(web): make ConfirmDialog Escape capture-phase to prevent leaking to ancestor modals
This commit is contained in:
@@ -25,13 +25,16 @@ export function ConfirmDialog({
|
|||||||
loading = false,
|
loading = false,
|
||||||
}: ConfirmDialogProps) {
|
}: ConfirmDialogProps) {
|
||||||
const handleKeyDown = useCallback((e: KeyboardEvent) => {
|
const handleKeyDown = useCallback((e: KeyboardEvent) => {
|
||||||
if (e.key === 'Escape' && !loading) onClose();
|
if (e.key === 'Escape' && !loading) {
|
||||||
|
e.stopPropagation();
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
}, [onClose, loading]);
|
}, [onClose, loading]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
document.addEventListener('keydown', handleKeyDown);
|
document.addEventListener('keydown', handleKeyDown, true);
|
||||||
return () => document.removeEventListener('keydown', handleKeyDown);
|
return () => document.removeEventListener('keydown', handleKeyDown, true);
|
||||||
}
|
}
|
||||||
}, [isOpen, handleKeyDown]);
|
}, [isOpen, handleKeyDown]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user