Skip to content

Bubble dragover and dragenter events #14

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

Merged
merged 4 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/file-attachment-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function onDragenter(event: DragEvent) {
if (dragging) {
clearTimeout(dragging)
}

dragging = window.setTimeout(() => target.removeAttribute('hover'), 200)

const transfer = event.dataTransfer
Expand All @@ -81,7 +82,6 @@ function onDragenter(event: DragEvent) {
transfer.dropEffect = 'copy'
target.setAttribute('hover', '')

event.stopPropagation()
event.preventDefault()
}

Expand Down
30 changes: 30 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,36 @@ describe('file-attachment', function () {
assert.equal('test.png', event.detail.attachments[0].file.name)
assert.equal(0, input.files.length)
})

it('bubbles the dragenter event after cancelling its default behavior', async function () {
const dataTransfer = new DataTransfer()
const file = new File(['hubot'], 'test.txt', {type: 'text/plain'})
dataTransfer.items.add(file)

const dragEvent = new DragEvent('dragenter', {bubbles: true, cancelable: true, dataTransfer})

const listener = once('dragenter')
input.dispatchEvent(dragEvent)

const event = await listener
assert.equal(dragEvent, event)
assert.equal(true, event.defaultPrevented)
})

it('bubbles the dragover event after cancelling its default behavior', async function () {
const dataTransfer = new DataTransfer()
const file = new File(['hubot'], 'test.txt', {type: 'text/plain'})
dataTransfer.items.add(file)

const dragEvent = new DragEvent('dragover', {bubbles: true, cancelable: true, dataTransfer})

const listener = once('dragover')
input.dispatchEvent(dragEvent)

const event = await listener
assert.equal(dragEvent, event)
assert.equal(true, event.defaultPrevented)
})
})
})

Expand Down