Skip to content

Commit 1c381c5

Browse files
committed
Picking a DOM node focuses the tree
1 parent 88e51ad commit 1c381c5

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/backend/agent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ export default class Agent extends EventEmitter {
479479
event.stopPropagation();
480480

481481
this.stopInspectingDOM();
482-
this._bridge.send('stopInspectingDOM');
482+
this._bridge.send('stopInspectingDOM', true);
483483
};
484484

485485
_onMouseDown = (event: MouseEvent) => {

src/devtools/views/Components/InspectHostNodesToggle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function InspectHostNodesToggle() {
1616
if (isChecked) {
1717
bridge.send('startInspectingDOM');
1818
} else {
19-
bridge.send('stopInspectingDOM');
19+
bridge.send('stopInspectingDOM', false);
2020
}
2121
},
2222
[bridge]

src/devtools/views/Components/Tree.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)