Skip to content

Commit ecb8df4

Browse files
committed
feat[Tree]: set initial scroll offset when inspected element index is set
1 parent 6356de4 commit ecb8df4

File tree

1 file changed

+20
-2
lines changed
  • packages/react-devtools-shared/src/devtools/views/Components

1 file changed

+20
-2
lines changed

packages/react-devtools-shared/src/devtools/views/Components/Tree.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,23 @@ export type ItemData = {
4949
treeFocused: boolean,
5050
};
5151

52-
type Props = {};
52+
function calculateInitialScrollOffset(
53+
inspectedElementIndex: number | null,
54+
elementHeight: number,
55+
): number | void {
56+
if (inspectedElementIndex === null) {
57+
return undefined;
58+
}
59+
60+
if (inspectedElementIndex < 3) {
61+
return undefined;
62+
}
63+
64+
// Make 3 elements on top of the inspected one visible
65+
return (inspectedElementIndex - 3) * elementHeight;
66+
}
5367

54-
export default function Tree(props: Props): React.Node {
68+
export default function Tree(): React.Node {
5569
const dispatch = useContext(TreeDispatcherContext);
5670
const {
5771
numElements,
@@ -426,6 +440,10 @@ export default function Tree(props: Props): React.Node {
426440
<FixedSizeList
427441
className={styles.List}
428442
height={height}
443+
initialScrollOffset={calculateInitialScrollOffset(
444+
inspectedElementIndex,
445+
lineHeight,
446+
)}
429447
innerElementType={InnerElementType}
430448
itemCount={numElements}
431449
itemData={itemData}

0 commit comments

Comments
 (0)