Skip to content

Commit f8cdd56

Browse files
committed
fix(webapp): preserve tree keyboard focus
1 parent 00fbf6a commit f8cdd56

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

  • apps/webapp/app/routes
    • _app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam
    • storybook.tree-view

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam/route.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -968,13 +968,10 @@ function TasksTreeView({
968968
},
969969
});
970970

971-
const getInteractiveNodeProps = useCallback(
972-
(id: string) => ({
973-
...getNodeProps(id),
974-
onClick: () => selectNode(id),
975-
}),
976-
[getNodeProps, selectNode]
977-
);
971+
const getInteractiveNodeProps = (id: string) => ({
972+
...getNodeProps(id),
973+
onClick: () => selectNode(id),
974+
});
978975

979976
return (
980977
<div className="grid h-full grid-rows-[2.5rem_1fr_3.25rem] overflow-hidden">
@@ -1077,6 +1074,7 @@ function TasksTreeView({
10771074
))}
10781075
<button
10791076
type="button"
1077+
tabIndex={-1}
10801078
disabled={!node.hasChildren}
10811079
aria-label={state.expanded ? "Collapse task" : "Expand task"}
10821080
className={cn(
@@ -1095,6 +1093,7 @@ function TasksTreeView({
10951093
toggleExpandNode(node.id);
10961094
}
10971095
scrollToNode(node.id);
1096+
parentRef.current?.focus();
10981097
}}
10991098
>
11001099
{node.hasChildren ? (

apps/webapp/app/routes/storybook.tree-view/route.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
FolderOpenIcon,
55
MagnifyingGlassIcon,
66
} from "@heroicons/react/20/solid";
7-
import { useCallback, useRef, useState } from "react";
7+
import { useRef, useState } from "react";
88
import { Button } from "~/components/primitives/Buttons";
99
import { Input } from "~/components/primitives/Input";
1010
import type { Tree } from "~/components/primitives/TreeView/TreeView";
@@ -177,13 +177,10 @@ function TreeViewParent({
177177
},
178178
});
179179

180-
const getInteractiveNodeProps = useCallback(
181-
(id: string) => ({
182-
...getNodeProps(id),
183-
onClick: () => toggleNodeSelection(id),
184-
}),
185-
[getNodeProps, toggleNodeSelection]
186-
);
180+
const getInteractiveNodeProps = (id: string) => ({
181+
...getNodeProps(id),
182+
onClick: () => toggleNodeSelection(id),
183+
});
187184

188185
return (
189186
<div className="flex w-72 flex-col items-start gap-y-4 p-4">
@@ -226,6 +223,7 @@ function TreeViewParent({
226223
>
227224
<button
228225
type="button"
226+
tabIndex={-1}
229227
aria-label={
230228
node.hasChildren
231229
? state.expanded
@@ -238,6 +236,7 @@ function TreeViewParent({
238236
e.stopPropagation();
239237
toggleExpandNode(node.id);
240238
selectNode(node.id, true);
239+
parentRef.current?.focus();
241240
}}
242241
>
243242
{node.hasChildren ? (

0 commit comments

Comments
 (0)