mirror of
				https://github.com/excalidraw/excalidraw.git
				synced 2025-10-31 10:54:33 +01:00 
			
		
		
		
	fix: context menu does not work after after dragging on StatsDragInput (#8386)
Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
		| @@ -136,22 +136,43 @@ const StatsDragInput = < | |||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   const handleInputValueRef = useRef(handleInputValue); |   const callbacksRef = useRef< | ||||||
|   handleInputValueRef.current = handleInputValue; |     Partial<{ | ||||||
|  |       handleInputValue: typeof handleInputValue; | ||||||
|  |       onPointerUp: (event: PointerEvent) => void; | ||||||
|  |       onPointerMove: (event: PointerEvent) => void; | ||||||
|  |     }> | ||||||
|  |   >({}); | ||||||
|  |   callbacksRef.current.handleInputValue = handleInputValue; | ||||||
|  |  | ||||||
|   // make sure that clicking on canvas (which umounts the component) |   // make sure that clicking on canvas (which umounts the component) | ||||||
|   // updates current input value (blur isn't triggered) |   // updates current input value (blur isn't triggered) | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     const input = inputRef.current; |     const input = inputRef.current; | ||||||
|  |     const callbacks = callbacksRef.current; | ||||||
|     return () => { |     return () => { | ||||||
|       const nextValue = input?.value; |       const nextValue = input?.value; | ||||||
|       if (nextValue) { |       if (nextValue) { | ||||||
|         handleInputValueRef.current( |         callbacks.handleInputValue?.( | ||||||
|           nextValue, |           nextValue, | ||||||
|           stateRef.current.originalElements, |           stateRef.current.originalElements, | ||||||
|           stateRef.current.originalAppState, |           stateRef.current.originalAppState, | ||||||
|         ); |         ); | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  |       // generally not needed, but in case `pointerup` doesn't fire and | ||||||
|  |       // we don't remove the listeners that way, we should at least remove | ||||||
|  |       // on unmount | ||||||
|  |       window.removeEventListener( | ||||||
|  |         EVENT.POINTER_MOVE, | ||||||
|  |         callbacks.onPointerMove!, | ||||||
|  |         false, | ||||||
|  |       ); | ||||||
|  |       window.removeEventListener( | ||||||
|  |         EVENT.POINTER_UP, | ||||||
|  |         callbacks.onPointerUp!, | ||||||
|  |         false, | ||||||
|  |       ); | ||||||
|     }; |     }; | ||||||
|   }, [ |   }, [ | ||||||
|     // we need to track change of `editable` state as mount/unmount |     // we need to track change of `editable` state as mount/unmount | ||||||
| @@ -248,10 +269,7 @@ const StatsDragInput = < | |||||||
|               }; |               }; | ||||||
|             }; |             }; | ||||||
|  |  | ||||||
|             window.addEventListener(EVENT.POINTER_MOVE, onPointerMove, false); |             const onPointerUp = () => { | ||||||
|             window.addEventListener( |  | ||||||
|               EVENT.POINTER_UP, |  | ||||||
|               () => { |  | ||||||
|               window.removeEventListener( |               window.removeEventListener( | ||||||
|                 EVENT.POINTER_MOVE, |                 EVENT.POINTER_MOVE, | ||||||
|                 onPointerMove, |                 onPointerMove, | ||||||
| @@ -267,9 +285,15 @@ const StatsDragInput = < | |||||||
|               originalElementsMap = null; |               originalElementsMap = null; | ||||||
|  |  | ||||||
|               document.body.classList.remove("excalidraw-cursor-resize"); |               document.body.classList.remove("excalidraw-cursor-resize"); | ||||||
|               }, |  | ||||||
|               false, |               window.removeEventListener(EVENT.POINTER_UP, onPointerUp, false); | ||||||
|             ); |             }; | ||||||
|  |  | ||||||
|  |             callbacksRef.current.onPointerMove = onPointerMove; | ||||||
|  |             callbacksRef.current.onPointerUp = onPointerUp; | ||||||
|  |  | ||||||
|  |             window.addEventListener(EVENT.POINTER_MOVE, onPointerMove, false); | ||||||
|  |             window.addEventListener(EVENT.POINTER_UP, onPointerUp, false); | ||||||
|           } |           } | ||||||
|         }} |         }} | ||||||
|         onPointerEnter={() => { |         onPointerEnter={() => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 zsviczian
					zsviczian