Skip to content
This repository was archived by the owner on Apr 17, 2022. It is now read-only.

Commit 5f267bf

Browse files
committed
fix: Menu positioning on fixed positioned parent (#18)
1 parent 3598732 commit 5f267bf

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/Vue3DatePicker/utils/composition/position.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@ export const usePosition = (openPosition: OpenPosition, uid: string): IUsePositi
2020
* Get correct offset of an element
2121
*/
2222
const getOffset = (el: HTMLElement): { top: number; left: number } => {
23-
let x = 0;
24-
let y = 0;
25-
while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
26-
x += el.offsetLeft - el.scrollLeft;
27-
y += el.offsetTop - el.scrollTop;
28-
el = el.offsetParent as HTMLElement;
29-
}
30-
return { top: y, left: x };
23+
const rect = el.getBoundingClientRect();
24+
return {
25+
left: rect.left + window.scrollX,
26+
top: rect.top + window.scrollY,
27+
};
3128
};
3229

3330
/**

0 commit comments

Comments
 (0)