@@ -18,7 +18,7 @@ import { PositionData } from './Types/PositionData';
18
18
* @returns object with a top and left value in the form `{number}px`
19
19
*/
20
20
function position ( options : IOptions ) : PositionData {
21
- const { _bodyRect, _anchorRect, _targetRect } = initialisePrivateFields ( ) ;
21
+ const { _bodyRect, _anchorRect, _targetRect, scrollableParents } = initialisePrivateFields ( ) ;
22
22
23
23
const myPos = Helpers . parse (
24
24
options . my ,
@@ -44,6 +44,7 @@ function position(options: IOptions): PositionData {
44
44
return {
45
45
left : calculateLeft ( myPos , atPos ) . value . toString ( ) + 'px' ,
46
46
top : calculateTop ( myPos , atPos ) . value . toString ( ) + 'px' ,
47
+ scrollableParents,
47
48
// @ts -ignore
48
49
...( options . debug === true
49
50
? { _bodyRect, _anchorRect, _targetRect }
@@ -56,6 +57,7 @@ function position(options: IOptions): PositionData {
56
57
return {
57
58
top : pos . top . toString ( ) + 'px' ,
58
59
left : pos . left . toString ( ) + 'px' ,
60
+ scrollableParents,
59
61
// @ts -ignore
60
62
...( options . debug === true
61
63
? { _bodyRect, _anchorRect, _targetRect }
@@ -84,7 +86,8 @@ function position(options: IOptions): PositionData {
84
86
const originalDisplay = options . target . style . display ;
85
87
options . target . style . display = 'block' ;
86
88
87
- const _targetRect = options . target . getBoundingClientRect ( ) ;
89
+ const _targetRect = options . target . getBoundingClientRect ( ) ,
90
+ scrollableParents : HTMLElement [ ] = [ ] ;
88
91
89
92
options . target . style . display = originalDisplay ;
90
93
@@ -93,8 +96,9 @@ function position(options: IOptions): PositionData {
93
96
let parent = options . anchor . parentElement ;
94
97
95
98
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 )
98
102
99
103
parent = parent . parentElement ;
100
104
}
@@ -111,6 +115,7 @@ function position(options: IOptions): PositionData {
111
115
_bodyRect,
112
116
_anchorRect,
113
117
_targetRect,
118
+ scrollableParents
114
119
} ;
115
120
}
116
121
0 commit comments