@@ -52,6 +52,7 @@ export default function Tree(props: Props) {
5252 // $FlowFixMe https://github.com/facebook/flow/issues/7341
5353 const listRef = useRef < FixedSizeList < ItemData > | null > ( null ) ;
5454 const treeRef = useRef < HTMLDivElement | null > ( null ) ;
55+ const focusTargetRef = useRef < HTMLDivElement | null > ( null ) ;
5556
5657 const [ treeFocused , setTreeFocused ] = useState < boolean > ( false ) ;
5758
@@ -69,6 +70,19 @@ export default function Tree(props: Props) {
6970 }
7071 } , [ listRef , selectedElementIndex ] ) ;
7172
73+ // Picking an element in the inspector should put focus into the tree.
74+ // This ensures that keyboard navigation works right after picking a node.
75+ useEffect ( ( ) => {
76+ function handleStopInspectingDOM ( didSelectNode ) {
77+ if ( didSelectNode && focusTargetRef . current !== null ) {
78+ focusTargetRef . current . focus ( ) ;
79+ }
80+ }
81+ bridge . addListener ( 'stopInspectingDOM' , handleStopInspectingDOM ) ;
82+ return ( ) =>
83+ bridge . removeListener ( 'stopInspectingDOM' , handleStopInspectingDOM ) ;
84+ } , [ bridge ] ) ;
85+
7286 // This ref is passed down the context to elements.
7387 // It lets them avoid autoscrolling to the same item many times
7488 // when a selected virtual row goes in and out of the viewport.
@@ -204,6 +218,7 @@ export default function Tree(props: Props) {
204218 onFocus = { handleFocus }
205219 onKeyPress = { handleKeyPress }
206220 onMouseLeave = { handleMouseLeave }
221+ ref = { focusTargetRef }
207222 tabIndex = { 0 }
208223 >
209224 < AutoSizer >
0 commit comments