When integrating with Bootstrap (if this needs to be logged with BS please let me know), I've noticed that when I set a container's min-height programmatically or statically to fill the viewport, the positioning of any tooltips within this container go off-center.
https://codepen.io/davcpas1234/full/KXxYdZ/
min-height calculated by jQuery to be equal to 100%Tooltip is displayed in correct position relative to element (a button in this example)
Tooltip is displayed off-center (screenshot from codepen):

Positioning resolves if resized when "displayed"

I'm suspecting that this has something to do with the scrollbar, as when the scrollbar is displayed the tooltips are displayed in the correct position:

I can't reproduce on Chrome 61

Hi @FezVrasta, I've updated the code pen. This issue is reflected correctly. Apologies!

Subsequently, I've discovered that this is not dependent on resolution, as originally thought.
I've created an additional codepen with a workaround, for my specific example: https://codepen.io/davcpas1234/full/OxeJXN
If I programmatically force-apply a 1px overflow, the tooltips are positioned correctly:

Side by side:

Hopefully this helps @FezVrasta 👍
I am also experiencing this. The tooltip is 9 pixels to the left of the center when the scrollbar isn't present.
I still can't reproduce it... Do I have to do something specific?
Hey.
I'm also experiencing this problem.
At first I was pretty confused cause the problem appeared only on the external monitor, not on my laptop’s screen. I could drag the same browser window from one to another and the behaviour of the tooltips changed. On the bigger screen tooltip is always shifted to the left – just about 17px.
So I’ve checked if it is somehow connected with the vertical scrollbar and the answer is “yes”.
When there is no scrollbar – the tooltips are shifted to the left.
This codepen shows the issue for me - but only without the scrollbar present.
https://codepen.io/davcpas1234/full/KXxYdZ/
Do you have any idea why?
Are you on Windows?
Yes, Windows 10 x64.
I've tested it on Chrome 62, Firefox 56 and Edge 15.
Also tested on 3 other PCs (Windows 7 and 10, Chrome, from my colleagues at work) and the bug shows in every case.
Are there any more details that I can share?
If you could record a little clip to show me how you reproduce it and how you don't it would be awesome.
You may use https://www.cockos.com/licecap/
Sure, here it is:

Also, as davcpas1234 mentioned in the first post, when you resize the window when the tooltip is displayed - the position gets fixed and the tooltip is centered as it should.
This issue is potentially linked to the below:
https://github.com/twbs/bootstrap/issues/25013
https://github.com/FezVrasta/popper.js/issues/510
@davcpas1234 Yep, and I'm even considering using a seperate library for tooltips because of this. Really annoying. Has anyone found a quick fix for this yet?
Even calling .tooltip('update') does not correct the issue.
@FezVrasta Here is a minimal reproduction using min-height: 100vh on the container.
https://codepen.io/anon/pen/paWMeV/
Version 63.0.3239.132 (Official Build) (64-bit) on macOS 10.13.3
I was seeing a similar issue and I figured out the root cause.
As was said previously, the situation arises when an element on the page has as height the entire viewport (100vh). Imagine the following DOM:
What happens is that right before the computation of the position of the popper, the popper gets position: absolute. However, since the popper appears after the page in the DOM, it will be positioned after it as well. Since the height of the page then becomes 100vh + height(popper), the scrollbar appears. This can be seen on https://codepen.io/anon/pen/zRaaLa.
So right before the position is computed, the scrollbar appears (whereas it was invisible before). As you can imagine, this messes it up and this is why the positioning is shifted just by the width of the scrollbar. After the computation is done, the popper is positioned and so the scrollbar disappears.
100vh height.See https://codepen.io/anon/pen/rJKKoK for why this works.
top: 0 on the popperThis would force the positioning of the popper while the computation is done. After, this property would be overridden as the library sets a top property in the style attribute.
@danwad Here is a fork of your Codepen where this fix is applied: https://codepen.io/anon/pen/GQGGmV. As you can see, the tooltip is correctly centered simply by adding .tooltip { top: 0; }.
Alternatively, I managed to fix it by surrounding the line https://github.com/FezVrasta/popper.js/blob/master/packages/popper/src/methods/update.js#L29 (call to getReferenceOffsets) with:
this.popper.style.top = 0;
data.offsets.reference = getReferenceOffsets(...);
this.popper.style.top = null;
This prevents the scrollbar from appearing when it matters, i.e. when computing the reference offsets. However, I'm not 100% sure that this fix won't mess up some other edge cases.
I hope this helps!
@YoranBrondsema could we set top to 0 before this line maybe?
https://github.com/FezVrasta/popper.js/blob/master/packages/popper/src/modifiers/applyStyle.js#L52
@FezVrasta Yes, that would actually even be better as you would only do it once. Once the top is set, it is never reset right?
The value of top will be overridden depending by the settings used by Popper.js, if gpuAcceleration is set to false it will be replaced with the top offset of the popper, if set to true, it will stay set to 0.
Feel free to send a PR.
FYI, this is also happening to me when I place the element as the last element in the body, while I have the height of
and as 100%.Solution 2 (setting top in the CSS) worked great for me!
Closing as dupe of #510, I think this is the only plausible solution?
Most helpful comment
I was seeing a similar issue and I figured out the root cause.
As was said previously, the situation arises when an element on the page has as height the entire viewport (
100vh). Imagine the following DOM:What happens is that right before the computation of the position of the popper, the popper gets
position: absolute. However, since the popper appears after the page in the DOM, it will be positioned after it as well. Since the height of the page then becomes100vh + height(popper), the scrollbar appears. This can be seen on https://codepen.io/anon/pen/zRaaLa.So right before the position is computed, the scrollbar appears (whereas it was invisible before). As you can imagine, this messes it up and this is why the positioning is shifted just by the width of the scrollbar. After the computation is done, the popper is positioned and so the scrollbar disappears.
Solution 1 (in client): place the popper element before any element on the page that has a
100vhheight.See https://codepen.io/anon/pen/rJKKoK for why this works.
Solution 2 (in client): set
top: 0on the popperThis would force the positioning of the popper while the computation is done. After, this property would be overridden as the library sets a
topproperty in thestyleattribute.@danwad Here is a fork of your Codepen where this fix is applied: https://codepen.io/anon/pen/GQGGmV. As you can see, the tooltip is correctly centered simply by adding
.tooltip { top: 0; }.Solution 3 (in library):
Alternatively, I managed to fix it by surrounding the line https://github.com/FezVrasta/popper.js/blob/master/packages/popper/src/methods/update.js#L29 (call to
getReferenceOffsets) with:This prevents the scrollbar from appearing when it matters, i.e. when computing the reference offsets. However, I'm not 100% sure that this fix won't mess up some other edge cases.
I hope this helps!