Improve Cmd+K focus reliability on web

This commit is contained in:
Mohamed Boudra
2026-02-04 12:15:36 +07:00
parent d839716e0c
commit 48cecdb6b5
4 changed files with 99 additions and 15 deletions
@@ -130,8 +130,16 @@ export function useGlobalKeyboardNav({
event.preventDefault();
const s = useKeyboardNavStore.getState();
if (!s.commandCenterOpen) {
const target =
event.target instanceof Element ? (event.target as Element) : null;
const targetEl =
target?.closest?.("textarea, input, [contenteditable='true']") ??
(target instanceof HTMLElement ? target : null);
const active = document.activeElement;
s.setFocusRestoreElement(active instanceof HTMLElement ? active : null);
const activeEl = active instanceof HTMLElement ? active : null;
s.setFocusRestoreElement(
(targetEl as HTMLElement | null) ?? activeEl ?? null
);
}
s.setCommandCenterOpen(!s.commandCenterOpen);
return;