Skip to content

Commit

Permalink
Merge pull request #217 from gravity-ui/fix-overscreen-tooltip
Browse files Browse the repository at this point in the history
fix: overscreen tooltip
  • Loading branch information
wd055 authored Aug 13, 2024
2 parents 1fb134e + 08e3337 commit 501c361
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/YagrCore/plugins/tooltip/placement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const NAMES = {
scrollOffset: ['pageYOffset', 'pageXOffset'],
offset: ['offsetY', 'offsetY'],
offsetOpt: ['yOffset', 'xOffset'],
bodyScroll: ['scrollHeight', 'scrollWidth'],
inner: ['innerHeight', 'innerWidth'],
};

interface Props {
Expand All @@ -26,6 +28,8 @@ interface Props {
scrollOffset: 'pageYOffset' | 'pageXOffset';
offset: 'offsetY' | 'offsetY';
offsetOpt: 'yOffset' | 'xOffset';
bodyScroll: 'scrollHeight' | 'scrollWidth';
inner: 'innerHeight' | 'innerWidth';
}

type Side = 'top' | 'bottom' | 'left' | 'right';
Expand Down Expand Up @@ -148,7 +152,8 @@ export default function (
// Set the position of the popup element along the primary axis using the
// anchor's bounding rect. If we are working in the context of position:
// absolute, then we will need to add the window's scroll position as well.
const scrollOffset = window[primary.scrollOffset] as unknown as number;
const maxOffset = document.body[primary.bodyScroll] - window[primary.inner];
const scrollOffset = Math.min(window[primary.scrollOffset] as unknown as number, maxOffset);

const boundPrimaryPos = (pos: number) => {
return Math.max(
Expand Down Expand Up @@ -179,7 +184,8 @@ export default function (
}

// Set the position of the popup element along the secondary axis.
const secondaryScrollOffset = window[secondary.scrollOffset] as unknown as number;
const maxSecondaryOffset = document.body[secondary.bodyScroll] - window[secondary.inner];
const secondaryScrollOffset = Math.min(window[secondary.scrollOffset] as unknown as number, maxSecondaryOffset);

elem.style[secondary.before] = px(
secondaryScrollOffset + boundSecondaryPos(anchorRect[secondary.before] - secondaryMarginBefore),
Expand Down

0 comments on commit 501c361

Please sign in to comment.