diff --git a/public/app/plugins/panel/canvas/ConnectionAnchors.tsx b/public/app/plugins/panel/canvas/ConnectionAnchors.tsx index 211617fe664..199cec648cd 100644 --- a/public/app/plugins/panel/canvas/ConnectionAnchors.tsx +++ b/public/app/plugins/panel/canvas/ConnectionAnchors.tsx @@ -7,10 +7,13 @@ import { ConnectionCoordinates } from 'app/features/canvas'; type Props = { setRef: (anchorElement: HTMLDivElement) => void; - handleMouseLeave: (event: React.MouseEvent | React.FocusEvent) => void; + handleMouseLeave: ( + event: React.MouseEvent | React.FocusEvent + ) => boolean; }; export const CONNECTION_ANCHOR_DIV_ID = 'connectionControl'; +export const CONNECTION_ANCHOR_ALT = 'connection anchor'; export const ConnectionAnchors = ({ setRef, handleMouseLeave }: Props) => { const highlightEllipseRef = useRef(null); @@ -38,7 +41,15 @@ export const ConnectionAnchors = ({ setRef, handleMouseLeave }: Props) => { } }; - const connectionAnchorAlt = 'connection anchor'; + const handleMouseLeaveAnchors = ( + event: React.MouseEvent | React.FocusEvent + ) => { + const didHideAnchors = handleMouseLeave(event); + + if (didHideAnchors) { + onMouseLeaveHighlightElement(); + } + }; // Unit is percentage from the middle of the element // 0, 0 middle; -1, -1 bottom left; 1, 1 top right @@ -75,7 +86,7 @@ export const ConnectionAnchors = ({ setRef, handleMouseLeave }: Props) => { {connectionAnchorAlt} { return (
-
+
{ + // Return boolean indicates if connection anchors were hidden or not + handleMouseLeave = (event: React.MouseEvent | React.FocusEvent): boolean => { + // If mouse is leaving INTO the anchor image, don't remove div + if ( + event.relatedTarget instanceof HTMLImageElement && + event.relatedTarget.getAttribute('alt') === CONNECTION_ANCHOR_ALT + ) { + return false; + } + this.connectionAnchorDiv!.style.display = 'none'; + return true; }; connectionListener = (event: MouseEvent) => {