[tooltip] fix tootlip with bounds offset #204
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐛 Bug Fix
This PR fixes a pretty bad and somewhat esoteric bug for
<TooltipWithBounds />
in the@vx/tooltip
package. Since my PR that introduced optional padding/offsets for this component, it's been acting weird on the edges of containers:@conglei and I debugged this earlier today and what we think is happening is that the tooltip
width
is being compressed on the edge of charts (whenword-wrap
is set to allow wrapping) like the pic below, making itswidth
smaller andheight
larger (note this gif has boundary detection disabled).This smaller
width
and largerheight
are reflected in thewithBoundingClientRect
s we get, but it seems because the tooltip is actually offset from the edge of the chart it does not visually appear to change dimensions. This means that our calculation for the offset includes a smaller-than-actual-width
and larger-than-actual-height
, making the tooltip go all over (if you pay close attn to the broken gif, it's consistent with this).The fix was to switch to using css transforms instead of
top
andleft
. We settop
to0
meaning that thewithBoundingClientRect
s dimensions are always in sync with the rendered tooltip:cc @techniq