fix(base): close view popovers on Escape regardless of focus; drop redundant property switch tab stop

This commit is contained in:
Philipinho
2026-06-15 05:23:19 +01:00
parent 1b5c081e1e
commit 07bfa3ba73
4 changed files with 23 additions and 0 deletions
@@ -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]);
}