feat(useMouseInElement): add support for tracking inline-level elements - #5049
Conversation
|
Added an inline-element demo (or if link is dead, go to the latest deploy-preview and search for |
| if (!isOutside.value) | ||
| break |
There was a problem hiding this comment.
For inline elements, if we're inside the current rect,
there's no need to check the others coming after it.
This also avoids the state of the other rects from overwriting
the fact that we're hovering on the current rect.
@vueuse/components
@vueuse/core
@vueuse/electron
@vueuse/firebase
@vueuse/integrations
@vueuse/math
@vueuse/metadata
@vueuse/nuxt
@vueuse/router
@vueuse/rxjs
@vueuse/shared
commit: |
|
...not sure who is the right person to reach out to for approval or feedback on if this change is desirable. |
|
@9romise could you merge this if it looks good to you? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5049 +/- ##
==========================================
+ Coverage 63.95% 63.97% +0.01%
==========================================
Files 343 343
Lines 7838 7841 +3
Branches 2424 2413 -11
==========================================
+ Hits 5013 5016 +3
Misses 2286 2286
Partials 539 539 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
To prevent regressions, I think it would be best to add some test cases to this PR after #5101 has been merged. Once other members also approve this request, we can proceed with merging. |
|
@9romise thanks for adding the tests! 🎉 |
cc @9romise —— any chance we could get someone to review/merge this? since it's been stalled for over a month now and we already added the tests. |
Before submitting the PR, please make sure you do the following
fixes #123).Description
Current Behavior
useMouseInElementworks perfectly for block elements, but does not work correctly for inline elements. This is because it usesel.getBoundingClientRect(), which returns a single rect that wraps the entire element. For inline elements, this means that this rect will potentially include parts that are not in the element itself.For example, the regions marked with
xbelow would be detected as being in the inline element when hovered.Proposed Behavior
Instead of using
el.getBoundingClientRect(), we can useel.getClientRects()to get more precise bounding.Per the docs:
For example, in the above scenario, we'll get three rects returned, the first one containing
"here is the inline", the second rect containing"element which wraps onto this line", and the third element containing"and ends here."And hovering on the
xregions will no longer be detected as being still within the inline element.Note
Since
getClientRectsreturns a singleDOMRectfor block elements (see second paragraph in the quoted text above, or check the documentation source), there should be no regression in performance for block elements.