Browse Source

fix: do not refocus element link input on unrelated updates (#9037)

David Luzar 6 months ago
parent
commit
ec06fbc1fc
1 changed files with 7 additions and 13 deletions
  1. 7 13
      packages/excalidraw/components/hyperlink/Hyperlink.tsx

+ 7 - 13
packages/excalidraw/components/hyperlink/Hyperlink.tsx

@@ -171,15 +171,17 @@ export const Hyperlink = ({
   }, [handleSubmit]);
 
   useEffect(() => {
-    let timeoutId: number | null = null;
-
     if (
-      inputRef &&
-      inputRef.current &&
+      isEditing &&
+      inputRef?.current &&
       !(device.viewport.isMobile || device.isTouchScreen)
     ) {
       inputRef.current.select();
     }
+  }, [isEditing, device.viewport.isMobile, device.isTouchScreen]);
+
+  useEffect(() => {
+    let timeoutId: number | null = null;
 
     const handlePointerMove = (event: PointerEvent) => {
       if (isEditing) {
@@ -207,15 +209,7 @@ export const Hyperlink = ({
         clearTimeout(timeoutId);
       }
     };
-  }, [
-    appState,
-    element,
-    isEditing,
-    setAppState,
-    elementsMap,
-    device.viewport.isMobile,
-    device.isTouchScreen,
-  ]);
+  }, [appState, element, isEditing, setAppState, elementsMap]);
 
   const handleRemove = useCallback(() => {
     trackEvent("hyperlink", "delete");