Skip to content

Commit cce4b5f

Browse files
fix(js): support panel scroll top position in all browsers (#595)
1 parent 527670e commit cce4b5f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/autocomplete-js/src/getPanelPlacementStyle.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ export function getPanelPlacementStyle({
1515
environment,
1616
}: GetPanelPlacementStyleParams) {
1717
const containerRect = container.getBoundingClientRect();
18-
const top =
19-
environment.document.body.scrollTop +
20-
containerRect.top +
21-
containerRect.height;
18+
// Some browsers have specificities to retrieve the document scroll position.
19+
// See https://stackoverflow.com/a/28633515/9940315
20+
const scrollTop =
21+
(environment.pageYOffset as number) ||
22+
environment.document.documentElement.scrollTop ||
23+
environment.document.body.scrollTop ||
24+
0;
25+
const top = scrollTop + containerRect.top + containerRect.height;
2226

2327
switch (panelPlacement) {
2428
case 'start': {

0 commit comments

Comments
 (0)