From a97b5c07b033e0c7f5be5618bb2fdebc03262a55 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 27 May 2019 19:03:40 +0100 Subject: [PATCH] [Flare] More fixes for getAbsoluteBoundingClientRect (#15746) --- packages/react-events/src/Press.js | 17 +++++++++++------ .../src/__tests__/Press-test.internal.js | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/react-events/src/Press.js b/packages/react-events/src/Press.js index d9111a7c8b..349e4613da 100644 --- a/packages/react-events/src/Press.js +++ b/packages/react-events/src/Press.js @@ -459,12 +459,17 @@ function getAbsoluteBoundingClientRect( // are fixed position, using offsetParent node for a fast-path. // We need to check both as offsetParent accounts for both // itself and the parent; so we need to align with that API. - // If these all pass, we can stop traversing the tree. - if ( - (scrollLeft !== 0 || scrollTop !== 0) && - (isNodeFixedPositioned(parent) || isNodeFixedPositioned(node)) - ) { - break; + // If these all pass, we can skip traversing the relevant + // node and go directly to its parent. + if (scrollLeft !== 0 || scrollTop !== 0) { + if (isNodeFixedPositioned(parent)) { + node = ((parent: any): Node).parentNode; + continue; + } + if (isNodeFixedPositioned(node)) { + node = parent; + continue; + } } offsetX += scrollLeft; offsetY += scrollTop; diff --git a/packages/react-events/src/__tests__/Press-test.internal.js b/packages/react-events/src/__tests__/Press-test.internal.js index 46bb14fd72..471ea3a69d 100644 --- a/packages/react-events/src/__tests__/Press-test.internal.js +++ b/packages/react-events/src/__tests__/Press-test.internal.js @@ -1232,7 +1232,7 @@ describe('Event responder: Press', () => { document.firstElementChild.scrollTop = 1000; const updatedCoordinatesInside = { pageX: coordinatesInside.pageX, - pageY: coordinatesInside.pageY + 100, + pageY: coordinatesInside.pageY + 1100, }; ref.current.dispatchEvent( createEvent('pointerdown', updatedCoordinatesInside),