Skip to content

Commit

Permalink
feat[Tree]: set initial scroll offset when inspected element index is…
Browse files Browse the repository at this point in the history
… set
  • Loading branch information
hoxyq committed Jan 7, 2025
1 parent 6356de4 commit ecb8df4
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,23 @@ export type ItemData = {
treeFocused: boolean,
};

type Props = {};
function calculateInitialScrollOffset(
inspectedElementIndex: number | null,
elementHeight: number,
): number | void {
if (inspectedElementIndex === null) {
return undefined;
}

if (inspectedElementIndex < 3) {
return undefined;
}

// Make 3 elements on top of the inspected one visible
return (inspectedElementIndex - 3) * elementHeight;
}

export default function Tree(props: Props): React.Node {
export default function Tree(): React.Node {
const dispatch = useContext(TreeDispatcherContext);
const {
numElements,
Expand Down Expand Up @@ -426,6 +440,10 @@ export default function Tree(props: Props): React.Node {
<FixedSizeList
className={styles.List}
height={height}
initialScrollOffset={calculateInitialScrollOffset(
inspectedElementIndex,
lineHeight,
)}
innerElementType={InnerElementType}
itemCount={numElements}
itemData={itemData}
Expand Down

0 comments on commit ecb8df4

Please sign in to comment.