44 FolderOpenIcon ,
55 MagnifyingGlassIcon ,
66} from "@heroicons/react/20/solid" ;
7- import { useRef , useState } from "react" ;
7+ import { useCallback , useRef , useState } from "react" ;
88import { Button } from "~/components/primitives/Buttons" ;
99import { Input } from "~/components/primitives/Input" ;
1010import type { Tree } from "~/components/primitives/TreeView/TreeView" ;
@@ -177,6 +177,14 @@ function TreeViewParent({
177177 } ,
178178 } ) ;
179179
180+ const getInteractiveNodeProps = useCallback (
181+ ( id : string ) => ( {
182+ ...getNodeProps ( id ) ,
183+ onClick : ( ) => toggleNodeSelection ( id ) ,
184+ } ) ,
185+ [ getNodeProps , toggleNodeSelection ]
186+ ) ;
187+
180188 return (
181189 < div className = "flex w-72 flex-col items-start gap-y-4 p-4" >
182190 < div className = "flex items-center gap-2" >
@@ -203,7 +211,7 @@ function TreeViewParent({
203211 autoFocus
204212 tree = { tree }
205213 nodes = { nodes }
206- getNodeProps = { getNodeProps }
214+ getNodeProps = { getInteractiveNodeProps }
207215 getTreeProps = { getTreeProps }
208216 parentClassName = "h-96 bg-background-deep"
209217 renderNode = { ( { node, state, index, virtualizer, virtualItem } ) => (
@@ -215,20 +223,22 @@ function TreeViewParent({
215223 "flex cursor-pointer items-center gap-2 py-1 hover:bg-blue-500/10" ,
216224 state . selected && "bg-blue-500/20 hover:bg-blue-500/30"
217225 ) }
218- onClick = { ( ) => {
219- toggleNodeSelection ( node . id ) ;
220- } }
221226 >
222- < div
223- className = "h-4 w-4"
227+ < button
228+ type = "button"
229+ aria-label = {
230+ node . hasChildren
231+ ? state . expanded
232+ ? "Collapse node"
233+ : "Expand node"
234+ : "Select node"
235+ }
236+ className = "h-4 w-4 focus-custom"
224237 onClick = { ( e ) => {
225238 e . stopPropagation ( ) ;
226239 toggleExpandNode ( node . id ) ;
227240 selectNode ( node . id , true ) ;
228241 } }
229- onKeyDown = { ( e ) => {
230- console . log ( e . key ) ;
231- } }
232242 >
233243 { node . hasChildren ? (
234244 state . expanded ? (
@@ -239,7 +249,7 @@ function TreeViewParent({
239249 ) : (
240250 < DocumentIcon className = "h-4 w-4" />
241251 ) }
242- </ div >
252+ </ button >
243253 < div > { node . data . title } </ div >
244254 </ div >
245255 ) }
0 commit comments