From f2e60f52d22a28da06fa6ddc70dee007f51a0df2 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 6 Oct 2025 17:54:52 +0300 Subject: [PATCH] feat(collections/board): restore focus --- apps/client/src/widgets/collections/board/card.tsx | 4 ++-- apps/client/src/widgets/collections/board/index.tsx | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/client/src/widgets/collections/board/card.tsx b/apps/client/src/widgets/collections/board/card.tsx index 4317d829c..2879f3a43 100644 --- a/apps/client/src/widgets/collections/board/card.tsx +++ b/apps/client/src/widgets/collections/board/card.tsx @@ -63,7 +63,7 @@ export default function Card({ setBranchIdToEdit?.(branch.branchId); }, [ setBranchIdToEdit, branch ]); - const handleKeyUp = useCallback((e: KeyboardEvent) => { + const handleKeyDown = useCallback((e: KeyboardEvent) => { if (e.key === "Enter") { api.openNote(note.noteId); } else if (e.key === "F2") { @@ -91,7 +91,7 @@ export default function Card({ onDragEnd={handleDragEnd} onContextMenu={handleContextMenu} onClick={!isEditing ? handleOpen : undefined} - onKeyUp={handleKeyUp} + onKeyDown={handleKeyDown} style={{ display: !isVisible ? "none" : undefined }} diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx index 2e8add6b4..26757229d 100644 --- a/apps/client/src/widgets/collections/board/index.tsx +++ b/apps/client/src/widgets/collections/board/index.tsx @@ -227,10 +227,12 @@ export function TitleEditor({ currentValue, placeholder, save, dismiss, multilin isNewItem?: boolean; }) { const inputRef = useRef(null); + const focusElRef = useRef(null); const dismissOnNextRefreshRef = useRef(false); const shouldDismiss = useRef(false); useEffect(() => { + focusElRef.current = document.activeElement; inputRef.current?.focus(); inputRef.current?.select(); }, [ inputRef ]); @@ -254,8 +256,11 @@ export function TitleEditor({ currentValue, placeholder, save, dismiss, multilin onKeyDown={(e: TargetedKeyboardEvent) => { if (e.key === "Enter" || e.key === "Escape") { e.preventDefault(); + e.stopPropagation(); shouldDismiss.current = (e.key === "Escape"); - e.currentTarget.blur(); + if (focusElRef.current instanceof HTMLElement) { + focusElRef.current.focus(); + } } }} onBlur={(newValue) => {