@@ -18,7 +18,7 @@ import { PositionData } from './Types/PositionData';
1818 * @returns  object with a top and left value in the form `{number}px` 
1919 */ 
2020function  position ( options : IOptions ) : PositionData  { 
21-     const  {  _bodyRect,  _anchorRect,  _targetRect }  =  initialisePrivateFields ( ) ; 
21+     const  {  _bodyRect,  _anchorRect,  _targetRect,  scrollableParents  }  =  initialisePrivateFields ( ) ; 
2222
2323    const  myPos  =  Helpers . parse ( 
2424            options . my , 
@@ -44,6 +44,7 @@ function position(options: IOptions): PositionData {
4444        return  { 
4545            left : calculateLeft ( myPos ,  atPos ) . value . toString ( )  +  'px' , 
4646            top : calculateTop ( myPos ,  atPos ) . value . toString ( )  +  'px' , 
47+             scrollableParents, 
4748            // @ts -ignore 
4849            ...( options . debug  ===  true 
4950                ? {  _bodyRect,  _anchorRect,  _targetRect } 
@@ -56,6 +57,7 @@ function position(options: IOptions): PositionData {
5657    return  { 
5758        top : pos . top . toString ( )  +  'px' , 
5859        left : pos . left . toString ( )  +  'px' , 
60+         scrollableParents, 
5961        // @ts -ignore 
6062        ...( options . debug  ===  true 
6163            ? {  _bodyRect,  _anchorRect,  _targetRect } 
@@ -84,7 +86,8 @@ function position(options: IOptions): PositionData {
8486        const  originalDisplay  =  options . target . style . display ; 
8587        options . target . style . display  =  'block' ; 
8688
87-         const  _targetRect  =  options . target . getBoundingClientRect ( ) ; 
89+         const  _targetRect  =  options . target . getBoundingClientRect ( ) , 
90+             scrollableParents  : HTMLElement [ ]  =  [ ] ; 
8891
8992        options . target . style . display  =  originalDisplay ; 
9093
@@ -93,8 +96,9 @@ function position(options: IOptions): PositionData {
9396            let  parent  =  options . anchor . parentElement ; 
9497
9598            while  ( parent  !==  null  &&  parent . tagName  !==  'HTML' )  { 
96-                 _anchorRect . y  +=  parent . scrollTop ; 
97-                 _anchorRect . x  +=  parent . scrollLeft ; 
99+                 // Check if scrollable 
100+                 if  ( parent . scrollHeight  >  parent . clientHeight ) 
101+                     scrollableParents . push ( parent ) 
98102
99103                parent  =  parent . parentElement ; 
100104            } 
@@ -111,6 +115,7 @@ function position(options: IOptions): PositionData {
111115            _bodyRect, 
112116            _anchorRect, 
113117            _targetRect, 
118+             scrollableParents
114119        } ; 
115120    } 
116121
0 commit comments