Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UploadDropZone: Child Element Handling in onDragLeave has issues #652

Closed
eduardbaitinger opened this issue Jan 10, 2024 · 3 comments
Closed
Labels

Comments

@eduardbaitinger
Copy link

Describe the bug
The shouldRemoveDragOver callback of UploadDropZone is only called if dragLeave event target is not the container and ignores the related target. This makes it impossible to control the end of dragging when the dropzone has child elements that should also be handled as part of dropzone.

In addition, the setting enableOnContains is also ignored in onDragLeave. This causes that dragging is canceled when dragging over child elements.

To Reproduce
Steps to reproduce the behavior:

  1. Create dropzone with child elements.
  2. Drag a file over a child of the dropzone container.
  3. The dragging is canceled and the dragOverClassName is removed.
    This behavior can't be fixed with shouldRemoveDragOver because it is not called when entering a direct child element of the dropzone.
    And also enableOnContains is not checked in onDragLeave.

Expected behavior
shouldRemoveDragOver should also be called for child elements of dropzone.
And if enableOnContains is set the dragging should not be canceled when entering a child element.

Versions
Specify the versions of the @rpldy packages you're using. -> v1.7.1
Which browser this bug reproduces in. -> Chrome

The reason should be the onDragLeave handler. It only checks event target but not the relatedTarget which is the target the dragover moves to and therefore important to decide if its inside or outside the dropzone container.

  const onDragLeave = useCallback(e => {
    if (dragLeaveTrackerRef.current && e.target === containerRef.current || shouldRemoveDragOver?.(e)) {
      handleEnd();
    }
  }, [handleEnd, containerRef, shouldRemoveDragOver]);

I think it could be implemented like this to fix both issues:

  const onDragLeave = useCallback(e => {
    if (dragLeaveTrackerRef.current && e.target === containerRef.current && (shouldRemoveDragOver?.(e) ?? !isOnTarget(e.relatedTarget, containerRef.current, enableOnContains))) {
      handleEnd();
    }
  }, [handleEnd, containerRef, shouldRemoveDragOver]);

I also changed isOnTarget so that it receives the element instead of the event.

@yoavniran
Copy link
Collaborator

thanks for the report @eduardbaitinger
I will look into it

@yoavniran
Copy link
Collaborator

fixed and released in 1.8.0

@eduardbaitinger
Copy link
Author

@yoavniran Thank you for the fix 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants