@@ -49,13 +49,18 @@ type GetViewDataResult = {
4949type GetViewData = (
5050 trigger : Element ,
5151 content : HTMLElement ,
52+ renderInPlace : boolean ,
5253) => GetViewDataResult ;
5354
54- const getViewData : GetViewData = ( trigger , content ) => {
55- const scroll = {
56- left : window . scrollX ,
57- top : window . scrollY ,
58- } ;
55+ const getViewData : GetViewData = ( trigger , content , renderInPlace ) => {
56+ let scroll = { left : window . pageXOffset , top : window . pageYOffset } ;
57+ if ( renderInPlace ) {
58+ scroll = {
59+ left : window . scrollX ,
60+ top : window . scrollY ,
61+ } ;
62+ }
63+
5964 const {
6065 left : triggerLeft ,
6166 top : triggerTop ,
@@ -72,8 +77,8 @@ const getViewData: GetViewData = (trigger, content) => {
7277 // The properties top and left of the trigger client rectangle need to be absolute to
7378 // the top left corner of the document as the value it's compared to is also the total
7479 // height and not only the viewport height (window client height + scroll offset).
75- triggerLeft : triggerLeft + window . scrollX ,
76- triggerTop : triggerTop + window . scrollY ,
80+ triggerLeft : triggerLeft + ( renderInPlace ? window . scrollX : 0 ) ,
81+ triggerTop : triggerTop + ( renderInPlace ? window . scrollY : 0 ) ,
7782 triggerWidth,
7883 triggerHeight,
7984 dropdownHeight,
@@ -96,7 +101,7 @@ export function calculateWormholedPosition(
96101 } : CalculatePositionOptions ,
97102) : CalculatePositionResult {
98103 // Collect information about all the involved DOM elements
99- const viewData = getViewData ( trigger , content ) ;
104+ const viewData = getViewData ( trigger , content , false ) ;
100105 const {
101106 scroll,
102107 triggerWidth,
@@ -293,7 +298,7 @@ export function calculateInPlacePosition(
293298 } else {
294299 // Automatically determine if there is enough space above or below
295300 const { triggerTop, triggerHeight, dropdownHeight, viewportBottom } =
296- getViewData ( trigger , content ) ;
301+ getViewData ( trigger , content , true ) ;
297302
298303 const enoughRoomBelow =
299304 triggerTop + triggerHeight + dropdownHeight < viewportBottom ;
0 commit comments