Skip to content

Commit

Permalink
fix: #911 isDragActive value when dragging over text on Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
avandecreme authored and rolandjitsu committed Apr 26, 2020
1 parent 828a833 commit 08a89cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/index.js
Expand Up @@ -487,10 +487,7 @@ export function useDropzone({
event.persist()
stopPropagation(event)

// Count the dropzone and any children that are entered.
if (dragTargetsRef.current.indexOf(event.target) === -1) {
dragTargetsRef.current = [...dragTargetsRef.current, event.target]
}
dragTargetsRef.current = [...dragTargetsRef.current, event.target]

if (isEvtWithFiles(event)) {
Promise.resolve(getFilesFromEvent(event)).then(draggedFiles => {
Expand Down Expand Up @@ -542,8 +539,14 @@ export function useDropzone({

// Only deactivate once the dropzone and all children have been left
const targets = dragTargetsRef.current.filter(
target => target !== event.target && rootRef.current && rootRef.current.contains(target)
target => rootRef.current && rootRef.current.contains(target)
)
// Make sure to remove a target present multiple times only once
// (Firefox may fire dragenter/dragleave multiple times on the same element)
const targetIdx = targets.indexOf(event.target)
if (targetIdx !== -1) {
targets.splice(targetIdx, 1)
}
dragTargetsRef.current = targets
if (targets.length > 0) {
return
Expand Down
6 changes: 6 additions & 0 deletions src/index.spec.js
Expand Up @@ -1878,6 +1878,12 @@ describe('useDropzone() hook', () => {
expect(dropzone).toHaveTextContent('dragAccept')
expect(dropzone).not.toHaveTextContent('dragReject')

fireDragLeave(dropzone, data)
await flushPromises(ui, container)
expect(dropzone).toHaveTextContent('dragActive')
expect(dropzone).toHaveTextContent('dragAccept')
expect(dropzone).not.toHaveTextContent('dragReject')

fireDragLeave(dropzone, data)
await flushPromises(ui, container)
expect(dropzone).not.toHaveTextContent('dragActive')
Expand Down

0 comments on commit 08a89cf

Please sign in to comment.