From 272103abce4ff5bf58f675a27916b1642c20168b Mon Sep 17 00:00:00 2001 From: Iurii Kucherov Date: Wed, 8 Jul 2015 00:59:05 +0300 Subject: [PATCH] Fix tooltip position If tooltip goes out of the left side, set position to 0 instead of negative offset (Closes #839) --- src/tooltip/tooltip.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 7e5ee4e1..80a167f4 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -60,8 +60,17 @@ MaterialTooltip.prototype.handleMouseEnter_ = function(event) { event.stopPropagation(); var props = event.target.getBoundingClientRect(); - this.element_.style.left = props.left + (props.width / 2) + 'px'; - this.element_.style.marginLeft = -1 * (this.element_.offsetWidth / 2) + 'px'; + var left = props.left + (props.width / 2); + var marginLeft = -1 * (this.element_.offsetWidth / 2); + + if (left + marginLeft < 0) { + this.element_.style.left = 0; + this.element_.style.marginLeft = 0; + } else { + this.element_.style.left = left + 'px'; + this.element_.style.marginLeft = marginLeft + 'px'; + } + this.element_.style.top = props.top + props.height + 10 + 'px'; this.element_.classList.add(this.CssClasses_.IS_ACTIVE); window.addEventListener('scroll', this.boundMouseLeaveHandler, false);