From 457f10c92b8d8d7bf0683b62788fef54f4e50f9f Mon Sep 17 00:00:00 2001 From: Damien Abos Date: Mon, 31 Aug 2015 15:30:53 +0200 Subject: [PATCH] fix(tooltip): correctly position tooltip - Use a style reset so the DOM recalculates values before correctly positioning the tooltip Closes #4311 Fixes #4195 --- src/tooltip/tooltip.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 4674d8ab65..b4e98914ce 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -132,13 +132,20 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.b var positionTooltip = function() { if (!tooltip) { return; } - - var ttPosition = $position.positionElements(element, tooltip, ttScope.placement, appendToBody); - ttPosition.top += 'px'; - ttPosition.left += 'px'; - - // Now set the calculated positioning. - tooltip.css(ttPosition); + + // Reset the positioning and box size for correct width and height values. + tooltip.css({ top: 0, left: 0, width: 'auto', height: 'auto' }); + + var ttBox = $position.position(tooltip); + var ttCss = $position.positionElements(element, tooltip, ttScope.placement, appendToBody); + ttCss.top += 'px'; + ttCss.left += 'px'; + + ttCss.width = ttBox.width + 'px'; + ttCss.height = ttBox.height + 'px'; + + // Now set the calculated positioning and size. + tooltip.css(ttCss); }; var positionTooltipAsync = function() {