From c93242b8840ec9c884c595d023c513b285644532 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Tue, 10 Aug 2021 08:13:52 +1000 Subject: [PATCH] Fix selection cursor getting stuck on selection remove --- src/components/konva/Selection.tsx | 41 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/components/konva/Selection.tsx b/src/components/konva/Selection.tsx index 9c4e25a..4cafaf9 100644 --- a/src/components/konva/Selection.tsx +++ b/src/components/konva/Selection.tsx @@ -146,35 +146,36 @@ function Selection({ // Update cursor when mouse enter and out of selection function handleMouseEnter(event: Konva.KonvaEventObject) { - let style = event.target.getStage()?.content?.style; - if (style && hasItems) { - style.cursor = "move"; + let stage = event.target.getStage(); + if (stage && hasItems) { + stage.content.style.cursor = "move"; } } function handleMouseOut(event: Konva.KonvaEventObject) { - let style = event.target.getStage()?.content?.style; - if (style) { - style.cursor = ""; + let stage = event.target.getStage(); + if (stage) { + stage.content.style.cursor = ""; } } - // Update cursor to move when selection is made + // Update cursor to move when selection is made or removed useEffect(() => { - if (hasItems) { - var node: Konva.Node | null = null; - if (lineRef.current) { - node = lineRef.current; - } else if (rectRef.current) { - node = rectRef.current; - } - if (node) { - let style = node.getStage()?.content?.style; - if (style) { - style.cursor = "move"; - } - } + var node: Konva.Node | null = null; + if (lineRef.current) { + node = lineRef.current; + } else if (rectRef.current) { + node = rectRef.current; } + let stage = node?.getStage(); + if (stage && hasItems) { + stage.content.style.cursor = "move"; + } + return () => { + if (stage) { + stage.content.style.cursor = ""; + } + }; }, [hasItems]); const requestRef = useRef();