mirror of
https://github.com/docmost/docmost.git
synced 2026-08-29 10:05:03 +08:00
fix(base): close view popovers on Escape regardless of focus; drop redundant property switch tab stop
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function useEscapeClose(opened: boolean, onClose: () => void) {
|
||||
useEffect(() => {
|
||||
if (!opened) return;
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape" && !e.defaultPrevented) onClose();
|
||||
};
|
||||
document.addEventListener("keydown", onKeyDown);
|
||||
return () => document.removeEventListener("keydown", onKeyDown);
|
||||
}, [opened, onClose]);
|
||||
}
|
||||
Reference in New Issue
Block a user