Skip to content

Commit b177dfa

Browse files
committed
fixup! fixup! adds f2 shortcut using a fakenode since it's outside the treeview struct
1 parent 8fb8dd5 commit b177dfa

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocSubPageItem.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,24 @@ export const DocSubPageItem = (props: TreeViewNodeProps<Doc>) => {
100100

101101
const handleKeyDown = (e: React.KeyboardEvent) => {
102102
// F2: focus first action button
103-
const shoulOpenActions = !menuOpen && node.isFocused;
104-
if (e.key === 'F2' && shoulOpenActions) {
103+
const shouldOpenActions = !menuOpen && node.isFocused;
104+
if (e.key === 'F2' && shouldOpenActions) {
105105
buttonOptionRef.current?.focus();
106106
e.stopPropagation();
107107
return;
108108
}
109109
};
110110

111+
const handleActionsOpenChange = (isOpen: boolean) => {
112+
setMenuOpen(isOpen);
113+
114+
// When the menu closes (via Escape or activating an option),
115+
// return focus to the tree item so focus is not lost.
116+
if (!isOpen) {
117+
node.focus();
118+
}
119+
};
120+
111121
return (
112122
<Box
113123
className="--docs-sub-page-item"
@@ -181,7 +191,7 @@ export const DocSubPageItem = (props: TreeViewNodeProps<Doc>) => {
181191
<DocTreeItemActions
182192
doc={doc}
183193
isOpen={menuOpen}
184-
onOpenChange={setMenuOpen}
194+
onOpenChange={handleActionsOpenChange}
185195
parentId={node.data.parentKey}
186196
onCreateSuccess={afterCreate}
187197
actionsRef={actionsRef}

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocTree.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ export const DocTree = ({ currentDoc }: DocTreeProps) => {
116116
[selectRoot, navigateToRoot, rootActionsOpen],
117117
);
118118

119+
// Handle menu open/close for root item - mirrors DocSubPageItem behavior
120+
const handleRootActionsOpenChange = useCallback((isOpen: boolean) => {
121+
setRootActionsOpen(isOpen);
122+
123+
// When the menu closes, return focus to the root tree item
124+
// (same behavior as DocSubPageItem for consistency)
125+
// Use requestAnimationFrame for smoother focus transition without flickering
126+
if (!isOpen) {
127+
requestAnimationFrame(() => {
128+
rootItemRef.current?.focus();
129+
});
130+
}
131+
}, []);
132+
119133
/**
120134
* This effect is used to reset the tree when a new document
121135
* that is not part of the current tree is loaded.
@@ -310,7 +324,7 @@ export const DocTree = ({ currentDoc }: DocTreeProps) => {
310324
}}
311325
isOpen={rootActionsOpen}
312326
isRoot={true}
313-
onOpenChange={setRootActionsOpen}
327+
onOpenChange={handleRootActionsOpenChange}
314328
actionsRef={rootActionsRef}
315329
buttonOptionRef={rootButtonOptionRef}
316330
/>

0 commit comments

Comments
 (0)