This repository was archived by the owner on Sep 21, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
packages/devtools-components/src Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments