Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/hooks/useDragAndDrop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const useDragAndDrop: UseDragAndDrop = ({
const [isDraggingOver, setIsDraggingOver] = useState(false);
const {close: closePopover} = usePopoverActions();

const dragCounter = useRef(0);
const debounceTimeoutRef = useRef<NodeJS.Timeout | null>(null);

// Reset drag state when the screen loses focus or becomes disabled
Expand All @@ -43,7 +42,6 @@ const useDragAndDrop: UseDragAndDrop = ({
if (isFocused && !isDisabled) {
return;
}
dragCounter.current = 0;
if (debounceTimeoutRef.current) {
clearTimeout(debounceTimeoutRef.current);
debounceTimeoutRef.current = null;
Expand Down Expand Up @@ -100,23 +98,17 @@ const useDragAndDrop: UseDragAndDrop = ({
break;
case DRAG_ENTER_EVENT:
handleDragEvent(event);
dragCounter.current += 1;
if (dragCounter.current === 1 && !isDraggingOver) {
if (!isDraggingOver) {
setIsDraggingOver(true);
}
break;
case DRAG_LEAVE_EVENT:
dragCounter.current -= 1;
if (dragCounter.current <= 0) {
dragCounter.current = 0;
// Add small debounce to prevent rapid flickering
debounceTimeoutRef.current = setTimeout(() => {
setIsDraggingOver(false);
}, 50);
}
// Add small debounce to prevent rapid flickering
debounceTimeoutRef.current = setTimeout(() => {
setIsDraggingOver(false);
}, 50);
Comment on lines 105 to +109

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep active drop state until pointer leaves drop zone

This now clears isDraggingOver on every dragleave, but dragleave is also fired when moving between child elements inside the same drop zone. In that case the 50ms timer can flip the UI to inactive even though the file is still over the drop target, and dragover does not set it back to true (only dragenter does), so the highlight can disappear while still hovering. The removed counter previously guarded against these nested enter/leave transitions.

Useful? React with 👍 / 👎.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. @FitseTLT what do you think of this comment? Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dragleave is not fired when moving between child elements inside the same drop zone. And even if it did the previous guard wasn't functional at all as it would set the state to false on multiple dragleave events.

break;
case DROP_EVENT:
dragCounter.current = 0;
setIsDraggingOver(false);
onDrop(event);
break;
Expand Down
Loading