mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Permissions popup context iso
This commit is contained in:
26
ts/hooks/useEscapeHandling.ts
Normal file
26
ts/hooks/useEscapeHandling.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function useEscapeHandling(handleEscape?: () => unknown): void {
|
||||
useEffect(() => {
|
||||
if (!handleEscape) {
|
||||
return;
|
||||
}
|
||||
|
||||
const handler = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') {
|
||||
handleEscape();
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
};
|
||||
document.addEventListener('keydown', handler);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handler);
|
||||
};
|
||||
}, [handleEscape]);
|
||||
}
|
||||
Reference in New Issue
Block a user