Skip to content

Commit 9504a1c

Browse files
committed
fixup! fixup! adds f2 shortcut using a fakenode since it's outside the treeview struct
1 parent 0ac78a2 commit 9504a1c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
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}

0 commit comments

Comments
 (0)