Skip to content

Commit

Permalink
Picking a DOM node focuses the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Apr 10, 2019
1 parent 88e51ad commit 1c381c5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/backend/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export default class Agent extends EventEmitter {
event.stopPropagation();

this.stopInspectingDOM();
this._bridge.send('stopInspectingDOM');
this._bridge.send('stopInspectingDOM', true);
};

_onMouseDown = (event: MouseEvent) => {
Expand Down
2 changes: 1 addition & 1 deletion src/devtools/views/Components/InspectHostNodesToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function InspectHostNodesToggle() {
if (isChecked) {
bridge.send('startInspectingDOM');
} else {
bridge.send('stopInspectingDOM');
bridge.send('stopInspectingDOM', false);
}
},
[bridge]
Expand Down
15 changes: 15 additions & 0 deletions src/devtools/views/Components/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function Tree(props: Props) {
// $FlowFixMe https://github.com/facebook/flow/issues/7341
const listRef = useRef<FixedSizeList<ItemData> | null>(null);
const treeRef = useRef<HTMLDivElement | null>(null);
const focusTargetRef = useRef<HTMLDivElement | null>(null);

const [treeFocused, setTreeFocused] = useState<boolean>(false);

Expand All @@ -69,6 +70,19 @@ export default function Tree(props: Props) {
}
}, [listRef, selectedElementIndex]);

// Picking an element in the inspector should put focus into the tree.
// This ensures that keyboard navigation works right after picking a node.
useEffect(() => {
function handleStopInspectingDOM(didSelectNode) {
if (didSelectNode && focusTargetRef.current !== null) {
focusTargetRef.current.focus();
}
}
bridge.addListener('stopInspectingDOM', handleStopInspectingDOM);
return () =>
bridge.removeListener('stopInspectingDOM', handleStopInspectingDOM);
}, [bridge]);

// This ref is passed down the context to elements.
// It lets them avoid autoscrolling to the same item many times
// when a selected virtual row goes in and out of the viewport.
Expand Down Expand Up @@ -204,6 +218,7 @@ export default function Tree(props: Props) {
onFocus={handleFocus}
onKeyPress={handleKeyPress}
onMouseLeave={handleMouseLeave}
ref={focusTargetRef}
tabIndex={0}
>
<AutoSizer>
Expand Down

0 comments on commit 1c381c5

Please sign in to comment.