This commit is contained in:
Olivier Gagnon
2021-12-20 15:48:26 -05:00
parent ddd0eaaf5c
commit 41a7109baa
7 changed files with 33 additions and 14 deletions
+10
View File
@@ -32,6 +32,16 @@ export function AlertManager(): React.ReactElement {
[],
);
useEffect(() => {
function handle(this: Document, event: KeyboardEvent): void {
if (event.code === "Escape") {
setAlerts([]);
}
}
document.addEventListener("keydown", handle);
return () => document.removeEventListener("keydown", handle);
}, []);
function close(): void {
setAlerts((old) => {
return old.slice(1, 1e99);