fix(tooltip): fix tooltip position with scroll height and scroll width

This commit is contained in:
Sagi 2022-10-13 15:35:42 +08:00
parent 1a7999ea58
commit 3f71272584
2 changed files with 5 additions and 4 deletions

View File

@ -13,6 +13,8 @@ export function useTooltipPosition(
const rectifyGutter = 20;
const { scrollLeft, scrollTop } = document.documentElement;
const revertDirectionMap = new Map<RectDirection, RectDirection>(
[['top', 'bottom'], ['bottom', 'top'], ['left', 'right'], ['right', 'left']]
);
@ -185,12 +187,12 @@ export function useTooltipPosition(
tooltipBound,
tooltipBound
);
return { top, left, right };
return { top: top + scrollTop, left: left + scrollLeft, right };
});
const arrowPosition = computed<RectPosition>(() => {
const { top, left, right } = calculateArrowPosition(placement.value, hostBound, tooltipPosition.value, arrowBound);
return { top, left, right };
return { top: top + scrollTop, left: left + scrollLeft, right };
});
return { arrowPosition, tooltipPlacement, tooltipPosition };

View File

@ -36,8 +36,7 @@ export default defineComponent({
const tooltipStyle = computed(() => {
const styleObject = {
left: tooltipLeftPosition.value,
top: tooltipTopPosition.value,
right: tooltipRightPosition.value
top: tooltipTopPosition.value
};
return styleObject;
});