Skip to content

Commit 197649d

Browse files
committed
Surface event for file-attachment-dragged
The implementation for github/github#190219 needs an event to kick off finding the cursor position, and rather than bubbling the DragEvent it seems prudent to fire a CustomEvent solely used by that consumer. That'll avoid any unintended side effects in the document at large.
1 parent ac7dc52 commit 197649d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/file-attachment-element.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ function onDragenter(event: DragEvent) {
7373
if (dragging) {
7474
clearTimeout(dragging)
7575
}
76+
77+
const dragEvent = new CustomEvent('file-attachment-dragged', {
78+
bubbles: true,
79+
cancelable: true,
80+
detail: {
81+
dragEvent: event,
82+
attachmentElement: target
83+
}
84+
})
85+
target.dispatchEvent(dragEvent)
86+
7687
dragging = window.setTimeout(() => target.removeAttribute('hover'), 200)
7788

7889
const transfer = event.dataTransfer

test/test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ describe('file-attachment', function () {
124124
assert.equal('test.png', event.detail.attachments[0].file.name)
125125
assert.equal(0, input.files.length)
126126
})
127+
128+
it('fires a file-attachment-dragged event on dragenter', async function () {
129+
const listener = once('file-attachment-dragged')
130+
const dragEvent = new Event('dragenter', {bubbles: true})
131+
input.dispatchEvent(dragEvent)
132+
const event = await listener
133+
assert.equal(dragEvent, event.detail.dragEvent)
134+
assert.equal(fileAttachment, event.detail.attachmentElement)
135+
})
136+
137+
it('fires a file-attachment-dragged event on dragover', async function () {
138+
const listener = once('file-attachment-dragged')
139+
const dragEvent = new Event('dragover', {bubbles: true})
140+
input.dispatchEvent(dragEvent)
141+
const event = await listener
142+
assert.equal(dragEvent, event.detail.dragEvent)
143+
assert.equal(fileAttachment, event.detail.attachmentElement)
144+
})
127145
})
128146
})
129147

0 commit comments

Comments
 (0)