visx icon indicating copy to clipboard operation
visx copied to clipboard

TooltipInPortal with bound detection changes its behaviour during window scroll

Open dufia opened this issue 4 years ago • 3 comments

Example

Correct (tooltip detects there is a bounding box edge above and positions itself below the cursor):

Screenshot 2021-12-10 at 14 59 58

Incorrect (tooltip stops respecting the top bounding box edge):

Screenshot 2021-12-10 at 14 59 43

Code sandbox link.

Expected behaviour Regardless of how many charts or elements are on the page, tooltip bounding box behaviour is consistent.

This is unfortunately causing an issue in the app that I am working on. I have a full screen chart and tooltip is not respecting the top edge a bounding box. Goes off screen essentially. Can't really figure out what is going on. Thanks for any help!

dufia avatar Dec 10 '21 14:12 dufia

The problem appears to be here: https://github.com/airbnb/visx/blob/3484291a96a215c66b7c94ea0669cb83d41254ba/packages/visx-tooltip/src/tooltips/TooltipWithBounds.tsx#L49

Subtracting window.scrollY fixes the issue, although with possible unwanted side effects.

placeTooltipUp = top + offsetTop + ownBounds.height - window.scrollY > window.innerHeight;

dufia avatar Dec 14 '21 12:12 dufia

Hey @dufia sorry for the delayed reply, I was gone for all of December. I think this edge case applies only during scroll as you mention (if my window is big enough to fully display both charts, it behaves as expected)

I think your suggestion - window.scrollY could work, tho I'd want to test it a bit more. I think arguably we could change the default behavior since it would be overall more ideal than the current behavior (which could be considered a bug), and we could also make it controllable with a prop if folks wanted to opt in or out. lmk what you think, I'm happy to review a PR!

williaster avatar Jan 05 '22 00:01 williaster

any update on this issue?

mcapkovic avatar Jul 31 '22 17:07 mcapkovic