Skip to content

Commit f2813ee

Browse files
authored
[DevTools] feat[Tree]: set initial scroll offset when inspected element index is set (facebook#31968)
Stacked on facebook#31956. See [commit on top](facebook@ecb8df4). Use `initialScrollOffset` prop for `FixedSizeList` from `react-window`. This happens when user selects an element in built-in Elements panel in DevTools, and then opens Components panel from React DevTools - elements will be synced and corresponding React Element will be pre-selected, we just have to scroll to its position now.
1 parent d634548 commit f2813ee

File tree

1 file changed

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

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ export type ItemData = {
4747
treeFocused: boolean,
4848
};
4949

50+
function calculateInitialScrollOffset(
51+
inspectedElementIndex: number | null,
52+
elementHeight: number,
53+
): number | void {
54+
if (inspectedElementIndex === null) {
55+
return undefined;
56+
}
57+
58+
if (inspectedElementIndex < 3) {
59+
return undefined;
60+
}
61+
62+
// Make 3 elements on top of the inspected one visible
63+
return (inspectedElementIndex - 3) * elementHeight;
64+
}
65+
5066
export default function Tree(): React.Node {
5167
const dispatch = useContext(TreeDispatcherContext);
5268
const {
@@ -401,6 +417,10 @@ export default function Tree(): React.Node {
401417
<FixedSizeList
402418
className={styles.List}
403419
height={height}
420+
initialScrollOffset={calculateInitialScrollOffset(
421+
inspectedElementIndex,
422+
lineHeight,
423+
)}
404424
innerElementType={InnerElementType}
405425
itemCount={numElements}
406426
itemData={itemData}

0 commit comments

Comments
 (0)