Skip to content

Commit

Permalink
Moving mouseup handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrush89 committed May 22, 2023
1 parent d932466 commit dce1126
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/TreeView/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,19 @@ const Root: React.FC<TreeViewProps> = ({
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({
Expand Down Expand Up @@ -310,7 +309,7 @@ const Root: React.FC<TreeViewProps> = ({
aria-label={ariaLabel}
aria-labelledby={ariaLabelledby}
data-omit-spacer={flat}
onMouseDown={mouseDownHandler}
onMouseDown={onMouseDown}
>
{children}
</UlBox>
Expand Down

0 comments on commit dce1126

Please sign in to comment.