From dce11265baa2a871c162f80b4577dce9d92f2962 Mon Sep 17 00:00:00 2001 From: Joshua Rush Date: Mon, 22 May 2023 14:03:38 +0000 Subject: [PATCH] Moving mouseup handler --- src/TreeView/TreeView.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/TreeView/TreeView.tsx b/src/TreeView/TreeView.tsx index 96d81e746d0..0819c335c56 100644 --- a/src/TreeView/TreeView.tsx +++ b/src/TreeView/TreeView.tsx @@ -262,20 +262,19 @@ const Root: React.FC = ({ setAriaLiveMessage(message) }, []) - const mouseDownHandler = useCallback(() => { + const onMouseDown = useCallback(() => { mouseDownRef.current = true }, []) - const mouseUpHandler = useCallback(() => { - mouseDownRef.current = false - }, []) - useEffect(() => { - document.addEventListener('mouseup', mouseUpHandler) + function onMouseUp() { + mouseDownRef.current = false + } + document.addEventListener('mouseup', onMouseUp) return () => { - document.removeEventListener('mouseup', mouseUpHandler) + document.removeEventListener('mouseup', onMouseUp) } - }) + }, []) useRovingTabIndex({containerRef, mouseDownRef}) useTypeahead({ @@ -310,7 +309,7 @@ const Root: React.FC = ({ aria-label={ariaLabel} aria-labelledby={ariaLabelledby} data-omit-spacer={flat} - onMouseDown={mouseDownHandler} + onMouseDown={onMouseDown} > {children}