Skip to content

Commit

Permalink
fix(js): support panel scroll top position in all browsers (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed May 25, 2021
1 parent 527670e commit cce4b5f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/autocomplete-js/src/getPanelPlacementStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down

0 comments on commit cce4b5f

Please sign in to comment.