Skip to content

Commit c191872

Browse files
fix(ui): stop scrolling on leaving workflow sidebar for drag-drop (#4139)
* fix(ui): stop scrolling on leaving workflow sidebar for drag-drop * Address comments, fix hover state * address comments
1 parent c246f5c commit c191872

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-drag-drop.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,13 @@ export function useDragDrop(options: UseDragDropOptions = {}) {
252252
if (!isDragging) {
253253
isDraggingRef.current = true
254254
setIsDragging(true)
255+
} else if (scrollAnimationRef.current === null) {
256+
scrollAnimationRef.current = requestAnimationFrame(handleAutoScroll)
255257
}
256258

257259
return true
258260
},
259-
[isDragging]
261+
[isDragging, handleAutoScroll]
260262
)
261263

262264
const getSiblingItems = useCallback(
@@ -616,6 +618,34 @@ export function useDragDrop(options: UseDragDropOptions = {}) {
616618
siblingsCacheRef.current.clear()
617619
}, [])
618620

621+
useEffect(() => {
622+
if (!isDragging) return
623+
const container = scrollContainerRef.current
624+
if (!container) return
625+
const onLeave = (e: DragEvent) => {
626+
const related = e.relatedTarget as Node | null
627+
if (related && container.contains(related)) return
628+
if (scrollAnimationRef.current !== null) {
629+
cancelAnimationFrame(scrollAnimationRef.current)
630+
scrollAnimationRef.current = null
631+
}
632+
dropIndicatorRef.current = null
633+
setDropIndicator(null)
634+
setHoverFolderId(null)
635+
}
636+
const onWindowDrop = (e: DragEvent) => {
637+
const target = e.target as Node | null
638+
if (target && container.contains(target)) return
639+
handleDragEnd()
640+
}
641+
container.addEventListener('dragleave', onLeave)
642+
window.addEventListener('drop', onWindowDrop, true)
643+
return () => {
644+
container.removeEventListener('dragleave', onLeave)
645+
window.removeEventListener('drop', onWindowDrop, true)
646+
}
647+
}, [isDragging, handleDragEnd])
648+
619649
const setScrollContainer = useCallback((element: HTMLDivElement | null) => {
620650
scrollContainerRef.current = element
621651
}, [])

0 commit comments

Comments
 (0)