diff --git a/common/static/js/src/tooltip_manager.js b/common/static/js/src/tooltip_manager.js index d3fe0d1566e7..71db826a705d 100644 --- a/common/static/js/src/tooltip_manager.js +++ b/common/static/js/src/tooltip_manager.js @@ -32,9 +32,20 @@ }, getCoords: function(pageX, pageY) { + let left = pageX - 0.5 * this.tooltip.outerWidth(); + const top = pageY - (this.tooltip.outerHeight() + 15); + // Check if the tooltip is going off the right edge of the screen + if (left + this.tooltip.outerWidth() > window.innerWidth) { + left = window.innerWidth - this.tooltip.outerWidth(); + } + // Check if the tooltip is going off the left edge of the screen + if (left < 0) { + left = 0; + } + return { - left: pageX - 0.5 * this.tooltip.outerWidth(), - top: pageY - (this.tooltip.outerHeight() + 15) + left, + top, }; },