-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix: Chat - Link in end of line displays tooltip over text and not on link #27817
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8257c9
Fix: Chat - Link in end of line displays tooltip over text and not on…
ewanmellor 36ef9c8
Fix: Chat - Link in end of line displays tooltip over text and not on…
ewanmellor f21c41c
Fix: Chat - Link in end of line displays tooltip over text and not on…
ewanmellor b2000cd
Fix: Chat - Link in end of line displays tooltip over text and not on…
ewanmellor 3dc42e9
Fix: Chat - Link in end of line displays tooltip over text and not on…
ewanmellor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,6 +13,63 @@ import useWindowDimensions from '../../hooks/useWindowDimensions'; | |||||
|
||||||
const hasHoverSupport = DeviceCapabilities.hasHoverSupport(); | ||||||
|
||||||
/** | ||||||
* Choose the correct bounding box from the given list. | ||||||
* This is a helper function for chooseBoundingBox below. | ||||||
* | ||||||
* @param {Element} bbs The bounding boxes of DOM element being hovered over. | ||||||
* @param {number} clientX The X position from the MouseEvent. | ||||||
* @param {number} clientY The Y position from the MouseEvent. | ||||||
* @param {number} slop An allowed slop factor when searching for the bounding | ||||||
* box. If the user is moving the mouse quickly we can end up getting a | ||||||
* hover event with the position outside any of our bounding boxes. We retry | ||||||
* with a small slop factor in that case, so if we have a bounding box close | ||||||
* enough then we go with that. | ||||||
* @return {DOMRect | null} The chosen bounding box. null if we failed to find | ||||||
* a matching one, which can happen if the user is moving the mouse quickly | ||||||
* and the onHoverOver event actually fires outside the element bounding box. | ||||||
*/ | ||||||
function chooseBoundingBoxWithSlop(bbs, clientX, clientY, slop) { | ||||||
for (let i = 0; i < bbs.length; i++) { | ||||||
const bb = bbs[i]; | ||||||
if (bb.x - slop <= clientX && bb.x + bb.width + slop >= clientX && bb.y - slop <= clientY && bb.y + bb.height + slop >= clientY) { | ||||||
return bb; | ||||||
} | ||||||
} | ||||||
return null; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Choose the correct bounding box for the tooltip to be positioned against. | ||||||
* This handles the case where the target is wrapped across two lines, and | ||||||
* so we need to find the correct part (the one that the user is hovering | ||||||
* over) and show the tooltip there. | ||||||
* | ||||||
* @param {Element} target The DOM element being hovered over. | ||||||
* @param {number} clientX The X position from the MouseEvent. | ||||||
* @param {number} clientY The Y position from the MouseEvent. | ||||||
* @return {DOMRect} The chosen bounding box. | ||||||
*/ | ||||||
function chooseBoundingBox(target, clientX, clientY) { | ||||||
const bbs = target.getClientRects(); | ||||||
if (bbs.length === 1) { | ||||||
return bbs[0]; | ||||||
} | ||||||
let bb = chooseBoundingBoxWithSlop(bbs, clientX, clientY, 0); | ||||||
if (bb) { | ||||||
return bb; | ||||||
} | ||||||
// Retry with a slop factor, in case the user is moving the mouse quickly. | ||||||
bb = chooseBoundingBoxWithSlop(bbs, clientX, clientY, 5); | ||||||
if (bb) { | ||||||
return bb; | ||||||
} | ||||||
// Fall back to the full bounding box if we failed to find a matching one. | ||||||
// This could only happen if the user is moving the mouse very quickly | ||||||
// and they got it outside our slop above. | ||||||
return target.getBoundingClientRect(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
/** | ||||||
* A component used to wrap an element intended for displaying a tooltip. The term "tooltip's target" refers to the | ||||||
* wrapped element, which, upon hover, triggers the tooltip to be shown. | ||||||
|
@@ -43,6 +100,14 @@ function Tooltip(props) { | |||||
const isAnimationCanceled = useRef(false); | ||||||
const prevText = usePrevious(text); | ||||||
|
||||||
const target = useRef(null); | ||||||
const initialMousePosition = useRef({x: 0, y: 0}); | ||||||
|
||||||
const updateTargetAndMousePosition = useCallback((e) => { | ||||||
target.current = e.target; | ||||||
initialMousePosition.current = {x: e.clientX, y: e.clientY}; | ||||||
}, []); | ||||||
|
||||||
/** | ||||||
* Display the tooltip in an animation. | ||||||
*/ | ||||||
|
@@ -91,10 +156,15 @@ function Tooltip(props) { | |||||
if (bounds.width === 0) { | ||||||
setIsRendered(false); | ||||||
} | ||||||
setWrapperWidth(bounds.width); | ||||||
setWrapperHeight(bounds.height); | ||||||
setXOffset(bounds.x); | ||||||
setYOffset(bounds.y); | ||||||
// Choose a bounding box for the tooltip to target. | ||||||
// In the case when the target is a link that has wrapped onto | ||||||
// multiple lines, we want to show the tooltip over the part | ||||||
// of the link that the user is hovering over. | ||||||
const betterBounds = chooseBoundingBox(target.current, initialMousePosition.current.x, initialMousePosition.current.y); | ||||||
setWrapperWidth(betterBounds.width); | ||||||
setWrapperHeight(betterBounds.height); | ||||||
setXOffset(betterBounds.x); | ||||||
setYOffset(betterBounds.y); | ||||||
}; | ||||||
|
||||||
/** | ||||||
|
@@ -152,6 +222,7 @@ function Tooltip(props) { | |||||
onBoundsChange={updateBounds} | ||||||
> | ||||||
<Hoverable | ||||||
onMouseEnter={updateTargetAndMousePosition} | ||||||
onHoverIn={showTooltip} | ||||||
onHoverOut={hideTooltip} | ||||||
shouldHandleScroll={props.shouldHandleScroll} | ||||||
|
Oops, something went wrong.
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.
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.
I have been checking and I think the need for the tolerance is not related to moving the mouse quickly, I can reproduce the bug constantly and this seems due to the returned bbs values corresponding to the text fragments only and not the block. Let's have the tolerance always used and integrate this function inside
chooseBoundingBox