-
-
Notifications
You must be signed in to change notification settings - Fork 533
[BUG] Tooltip position not updated on scroll #1044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is not a bug. Updating the tooltip position while scrolling is not viable, so you must adjust your CSS/DOM structure accordingly. I'm not too sure how you'd go about it in your specific case, but I'd start with trying Maybe we should add a more in-depth explanation in our documentation/troubleshooting section about this, but that's pretty much it. @danielbarion please share your thoughts, or close this as "not planned" if you agree. |
Okay, it feels like a bug, because updating the tooltip position works for many cases perfectly. But just not with this CSS combination.
So that the direct parent of the anchor is not scrollable? |
In those cases, technically the tooltip position isn't changing, it's just retaining its position relative to the scrolling element. The issue arises when the anchor is placed inside a scrolling element, and the tooltip component is outside of it, so the reference moves and the tooltip doesn't. The position doesn't get recalculated because it would be too expensive to do so. Having thought a little more about this, I believe placing the tooltip component inside the scrolling element should be good enough. If it doesn't work, please let us know. |
It works for the vertical position, but the "overflow:scroll" of the parent container will mess up the placement of the tooltip (e.g. place="left" won't work). My entire goal was to close the tooltip on scroll, not updating its position. The 'closeOnScroll' however, does not work in this case, because the tooltip itself does not detect a scroll. Since placing it inside the scrollable container messes up the placement, the solution would be to detect general scroll events and manually close the tooltip. The drawback is that the wrong position is visible for the time of an animation or "delayHide". So both values need to be as small as possible. The only possible solution for this library that I can imagine is to include a prop called forcePlace, which makes sure that the desiredPlace is always the one specified. In this way the tooltip could be included in the scrollable container and the scrolling problems would be fixed. But maybe it is too much an edge case. Anyway, I think you can close this issue. Thanks for taking the time :) |
Hi guys, @Uni2K you can try the approach of writing the logic to close the tooltip from your side using a controlled state for the tooltip and add an event listener to switch the state when the scroll event happens. Thank you both for the discussion, I believe this will help other people with the same question. I'll close this ticket, but feel free to comment or create a new issue if you need. |
I wasn't aware this was the case. The intended behavior was to close when scrolling anywhere on the page. I'll have a look on this.
When closing from scrolling, the tooltip should probably ignore I'll reopen since it does seem to be a bug with |
@Uni2K We should be merging it soon, but until then you can check out
|
As mentioned on my last comment, we are soon to add a section on our troubleshooting regarding this. For the tooltip to close when using
This is by design. This is how you'd setup the tooltip to work with default behavior: import { offset, flip, shift } from '@floating-ui/dom'
function MyComponent() {
return (
<div>
...
<Tooltip
offset={10} // just for clarity for where `offset()` gets its parameter internally
middlewares={[offset(10), flip(), shift({ padding: 5 })]}
/>
</div>
)
}
On your case, try leaving just the offset (with whatever value you prefer, import { offset } from '@floating-ui/dom'
<Tooltip
middlewares={[offset(10)]}
/> |
You are referring to the "caution" section?
So, the scrolling element is the parent of the Tooltip, the anchor is nested inside other divs. Do I understand it correctly?
Just removing the flip would give a perfect result, but the tooltip is cut off at the left side. Which is, again, just due to the "overflow-scroll". After reading a bit in the floating-ui github and maybe related issues (floating-ui/floating-ui#112), I fear that there is just not a solution for this case. The overflow-scroll will always prevent the tooltip from being drawn correctly. :s |
That does seem like it would be the case. Until we can think of a way around this, closing the tooltip is probably the best alternative in cases like this. I've just realized that in several responses in this thread (fixed now), I referred to Here's a minimal working example. https://stackblitz.com/edit/stackblitz-starters-9exiwk?file=src%2FApp.tsx |
Fortunately, I only used the correct This example showcases my situation at that point: -> The solution would be to place the tooltip INSIDE the container. And when I do it, the tooltip is cut off (thats what I wrote above). Here is the example using your code: Any more suggestions? :s |
My final suggestion would be to have the tooltip outside the scrolling element (so it doesn't clip), and have the anchor elements as direct children to the scrolling element (so The only big obstacle I can imagine this would be for you is that it might not be trivial to have the anchor elements as direct children of the scrolling element. If that's the case, there's not much else I can think of, unless you'd be willing to have your own version of |
Unfortunately, I use a more complex layout which does not allow the anchors to be the direct children. It would just kill the UX. Anyway, @gabrieljablonski thank you very much for your time and for the tweaking of |
I've realized the "direct child" restriction was just me being extremely lazy. Try out Your first example with the package updated: https://stackblitz.com/edit/stackblitz-starters-dxxsod?file=src%2FApp.tsx |
Available on official release |
Describe the bug
Using a minimal setup like:
The position of the tooltip is not updated during scrolling. The problem can be seen here:

The solution is to remove either "overflow:scroll" or "display:flex" from the parent div of the anchor element.
If both are present, the bug will occur. It also does not make a difference where the Tooltip is placed (in which div/DOM element), as long as the anchor parent has both CSS properties, the bug will occur.
Version of Package
v5.14.0
To Reproduce
Use the code above.
Expected behavior
´The tooltip disappears (closeOnScroll==true) or at least it updates the position to follow the anchor element.
Desktop (please complete the following information if possible or delete this section):
The text was updated successfully, but these errors were encountered: