Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit 6cca4a5

Browse files
committed
Fix scrollNodeIntoView function.
Use boundlingClientRect of the scrolled parent to check if the node is visible or not.
1 parent af302cb commit 6cca4a5

File tree

1 file changed

+10
-5
lines changed
  • packages/devtools-components/src

1 file changed

+10
-5
lines changed

packages/devtools-components/src/tree.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ class Tree extends Component {
546546
if (item !== undefined) {
547547
const treeElement = this.treeRef;
548548
const element = document.getElementById(this.props.getKey(item));
549+
549550
if (element) {
550551
const {top, bottom} = element.getBoundingClientRect();
551552
const closestScrolledParent = node => {
@@ -559,16 +560,20 @@ class Tree extends Component {
559560
return closestScrolledParent(node.parentNode);
560561
};
561562
const scrolledParent = closestScrolledParent(treeElement);
563+
const scrolledParentRect = scrolledParent
564+
? scrolledParent.getBoundingClientRect()
565+
: null;
562566
const isVisible = !scrolledParent
563567
|| (
564-
top >= 0
565-
&& bottom <= scrolledParent.clientHeight
568+
top >= scrolledParentRect.top
569+
&& bottom <= scrolledParentRect.bottom
566570
);
567571

568572
if (!isVisible) {
569-
let scrollToTop =
570-
(!options.alignTo && top < 0)
571-
|| options.alignTo === "top";
573+
const {alignTo} = options;
574+
let scrollToTop = alignTo
575+
? alignTo === "top"
576+
: !scrolledParentRect || top < scrolledParentRect.top;
572577
element.scrollIntoView(scrollToTop);
573578
}
574579
}

0 commit comments

Comments
 (0)