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
improve hover outside handler logic #115
Conversation
This fixes flickering Tooltip with `trigger="hover"` when the Tooltip overlaps the Trigger and cursor is moved to the overlaping section. Hovering overlaping section triggers `mouseleave` on the Trigger, which runs `hideTooltip()` but as the Tooltip disappears, the cursor encounters the Trigger again, `mouseenter` is triggered which runs `showTooltip()` and so it continues ad infinituum. This solution relies on `mousemove` instead and compares the cursor position with DOMRect of the Trigger. Also, when the `interactive` prop is enabled, it takes DOMRect of the Tooltip into consideration. This solution fixes another bug, which will occur with `trigger="hover"` in conjunction with `interactive` and big offset. The offset will create gap which will hide the Tooltip before the user hovers over it, so the `interactive` would not work, since the Tooltip will never be hoverable. This change virtualy increases the DOMRect of the Trigger to reach the Tooltip DOMRect so hovering over gap keeps the Tooltip opened.
Codecov Report
@@ Coverage Diff @@
## master #115 +/- ##
==========================================
+ Coverage 90.97% 93.75% +2.77%
==========================================
Files 2 2
Lines 133 160 +27
Branches 38 54 +16
==========================================
+ Hits 121 150 +29
+ Misses 12 10 -2
Continue to review full report at Codecov.
|
src/usePopperTooltip.ts
Outdated
}; | ||
}, [triggerRef, isTriggeredBy, showTooltip, hideTooltip]); | ||
React.useEffect(() => { | ||
if (!visible || triggerRef == null || !isTriggeredBy('hover')) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This follows the same condition as hover
but it turns on only when visible
is truthy.
So the memo fix was definitely needed, but I'm wondering if instead of avoiding calculations on every What are the pros and cons here according to you? |
@mohsinulhaq the The second problem with the potential gap between Trigger and the Tooltip in The solution proposed here solves all the problems quite clearly without any caveats. If you are concerned with performance, I admit the |
@czabaj then how about attaching to |
@mohsinulhaq that sounds complicated, wouldn't be better to be free of thinking about when and why attach The more I think about it, the more I'm sure that this logic clearly expresses what you need to achieve -- hide the tooltip when the cursor leaves some area. The CSS |
@czabaj If you could re-use the same logic to integrate with the virtual element construct from react-popper that we are using for follow-cursor, that would be even better. |
Can you please elaborate more on this? I see the possibility to use only a single |
@czabaj yep, that's exactly what I meant |
@mohsinulhaq look at the changes, I also added tests for |
c54499a
to
894b6d0
Compare
@mohsinulhaq hold on, I identified one bug. The I must call |
@mohsinulhaq I added check which calls |
ok thanks @czabaj, will review it soon |
@czabaj can you allow edits to the PR/branch. I have some changes to push to this before merging. |
@mohsinulhaq the "Allow edits by maintainers" is checked, is there any more options? |
@czabaj I have removed the pointer-events none we were using for follow-cursor, because I don't think it's needed anymore after your change. Correct me if I'm wrong. |
@mohsinulhaq correct. |
@mohsinulhaq as finishing touch, I improved the test for the "gap between" and added ESLint suppression pragma for |
@czabaj shall I go ahead and merge it? |
@mohsinulhaq I'm confident. Go ahead! |
@mohsinulhaq It was a pleasure, I like the selection of tooling in the repo and the code is easy to follow. If this creates some regression, don't hesitate to mention me in the issue. I will be glad to help. |
Thanks 😄 |
This fixes the flickering problem when
trigger="hover"
and Trigger and Tooltip overlaps.Partially relates #114
First commit also fixes some memoization bugs.