From 556cffa9f3ad62b3d78cc09506373c606421d47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Tue, 25 May 2021 20:43:41 +0200 Subject: [PATCH] fix(js): support panel scroll top position in all browsers Some browsers have specificities to retrieve the document scroll position. See https://stackoverflow.com/a/28633515/9940315 --- .../autocomplete-js/src/getPanelPlacementStyle.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/autocomplete-js/src/getPanelPlacementStyle.ts b/packages/autocomplete-js/src/getPanelPlacementStyle.ts index 4d59eb21e..bd62e71a2 100644 --- a/packages/autocomplete-js/src/getPanelPlacementStyle.ts +++ b/packages/autocomplete-js/src/getPanelPlacementStyle.ts @@ -15,10 +15,14 @@ export function getPanelPlacementStyle({ environment, }: GetPanelPlacementStyleParams) { const containerRect = container.getBoundingClientRect(); - const top = - environment.document.body.scrollTop + - containerRect.top + - containerRect.height; + // Some browsers have specificities to retrieve the document scroll position. + // See https://stackoverflow.com/a/28633515/9940315 + const scrollTop = + (environment.pageYOffset as number) || + environment.document.documentElement.scrollTop || + environment.document.body.scrollTop || + 0; + const top = scrollTop + containerRect.top + containerRect.height; switch (panelPlacement) { case 'start': {