mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 04:50:36 +03:00
B: Prevent default behavior when ESC is intercepted
This commit is contained in:
parent
1e96ffe594
commit
78bd97ec51
|
@ -6,6 +6,8 @@ export function useEscapeKey(handleClose: () => void, isEnabled: boolean = true)
|
||||||
const handleEscKey = useCallback(
|
const handleEscKey = useCallback(
|
||||||
(event: KeyboardEvent) => {
|
(event: KeyboardEvent) => {
|
||||||
if (event.key === 'Escape') {
|
if (event.key === 'Escape') {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
handleClose();
|
handleClose();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -14,9 +16,9 @@ export function useEscapeKey(handleClose: () => void, isEnabled: boolean = true)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isEnabled) {
|
if (isEnabled) {
|
||||||
document.addEventListener('keyup', handleEscKey, false);
|
document.addEventListener('keydown', handleEscKey, false);
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('keyup', handleEscKey, false);
|
document.removeEventListener('keydown', handleEscKey, false);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, [handleEscKey, isEnabled]);
|
}, [handleEscKey, isEnabled]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user