Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Tooltip misplaced when closest positioned ancestor is body element #2038

Closed
aritzbastida opened this issue Apr 9, 2014 · 5 comments
Closed

Comments

@aritzbastida
Copy link

I'm using the tooltip component in an AngularJS application. The initial configuration was the default (tooltip-append-to-body=false).

Then, I noticed that my tooltip is misplaced when I scrolled down the window in Chrome. After some debugging, I realized that the closest ancestor which has a explicit position (offsetParent) was the "body" element. This element seems to be a bit special, because (at least in Chrome), is the only one for which both "scrollTop" and $window.pageYOffset properties get updated. For any other element, we will have pageYOffset updated when we scroll the window, and scrollTop, when we scroll the element (if made scrollable with overflow: scroll).

As a result, the geometry arithmetic in position() function will not work with the "body" element:
https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L47

Should I set "tooltip-append-to-body" directive to true when the body is the offsetParent? If so, I had another issue: If the body is positioned "relative" with top/left different to 0, the tooltip will be misplaced by that same amount. The reason lies here:

var positionTooltip = function (){
// Get the position of the directive element.
position = appendToBody ? $position.offset( element ) : $position.position( element );
}

The offset of the element is calculated from the top-left coordinates of the document, not necessarily the body (which can be offset relatively, as explained above).

If this is the intended way the code should work, I think the documentation (http://angular-ui.github.io/bootstrap/) should be updated to make the API a bit clearer, because the only way for me to understand this was debugging the code.

Thanks,
Aritz

@JonathanAaron
Copy link

Finding this post helped me out. I would have spent hours figuring out why my tooltips weren't lining up right in Chrome. Thanks Aritz!

@karianna
Copy link
Contributor

plunkr please

@wesleycho
Copy link
Contributor

@Foxandxss what do you think? Is this worth updating the docs for?

@Foxandxss
Copy link
Contributor

Well, to be honest, I have no idea about positioning, not my topic. Now, if the current implementation is OK but there is a behavior that is not documented, absolutely yes.

@icfantv
Copy link
Contributor

icfantv commented Oct 28, 2015

Closing in favor of #4762.

@icfantv icfantv closed this as completed Oct 28, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants