Skip to content

Commit 751cf85

Browse files
authored
Merge pull request #22457 from hoangzinh/df/17844
Fix The tooltip changes its position when changed the language preference
2 parents 0bdca70 + 3e0a2b8 commit 751cf85

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/styles/getTooltipStyles.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ function computeHorizontalShift(windowWidth, xOffset, componentWidth, tooltipWid
6767
* and the top edge of the wrapped component.
6868
* @param {Element} [tooltip] - The reference to the tooltip's root element
6969
* @param {Number} tooltipTargetWidth - The width of the tooltip's target
70+
* @param {Number} tooltipTargetHeight - The height of the tooltip's target
7071
* @returns {Boolean}
7172
*/
72-
function isOverlappingAtTop(xOffset, yOffset, tooltip, tooltipTargetWidth) {
73+
function isOverlappingAtTop(xOffset, yOffset, tooltip, tooltipTargetWidth, tooltipTargetHeight) {
7374
if (typeof document.elementFromPoint !== 'function') {
7475
return false;
7576
}
@@ -88,8 +89,8 @@ function isOverlappingAtTop(xOffset, yOffset, tooltip, tooltipTargetWidth) {
8889
const rectAtTargetCenterX = elementAtTargetCenterX.getBoundingClientRect();
8990

9091
// Ensure it's not overlapping with another element by checking if the yOffset is greater than the top of the element
91-
// and less than the bottom of the element
92-
const isOverlappingAtTargetCenterX = yOffset > rectAtTargetCenterX.top && yOffset < rectAtTargetCenterX.bottom;
92+
// and less than the bottom of the element. Also ensure the tooltip target is not completely inside the elementAtTargetCenterX by vertical direction
93+
const isOverlappingAtTargetCenterX = yOffset > rectAtTargetCenterX.top && yOffset < rectAtTargetCenterX.bottom && yOffset + tooltipTargetHeight > rectAtTargetCenterX.bottom;
9394

9495
return isOverlappingAtTargetCenterX;
9596
}
@@ -156,7 +157,7 @@ export default function getTooltipStyles(
156157
// If either a tooltip will try to render within GUTTER_WIDTH logical pixels of the top of the screen,
157158
// Or the wrapped component is overlapping at top-center with another element
158159
// we'll display it beneath its wrapped component rather than above it as usual.
159-
shouldShowBelow = yOffset - tooltipHeight < GUTTER_WIDTH || isOverlappingAtTop(xOffset, yOffset, tooltip, tooltipTargetWidth);
160+
shouldShowBelow = yOffset - tooltipHeight < GUTTER_WIDTH || isOverlappingAtTop(xOffset, yOffset, tooltip, tooltipTargetWidth, tooltipTargetHeight);
160161

161162
// When the tooltip size is ready, we can start animating the scale.
162163
scale = currentSize;

0 commit comments

Comments
 (0)