Skip to content

Commit 004840f

Browse files
committed
Add support for input.files
1 parent 5745215 commit 004840f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/file-attachment-element.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FileAttachmentElement extends HTMLElement {
88
this.addEventListener('dragleave', onDragleave)
99
this.addEventListener('drop', onDrop)
1010
this.addEventListener('paste', onPaste)
11+
this.addEventListener('change', onChange)
1112
}
1213

1314
get directory(): boolean {
@@ -132,3 +133,16 @@ function onPaste(event: ClipboardEvent) {
132133
container.attach(files)
133134
event.preventDefault()
134135
}
136+
137+
function onChange(event: Event) {
138+
const container = event.currentTarget
139+
if (!(container instanceof FileAttachmentElement)) return
140+
const input = event.target
141+
if (!(input instanceof HTMLInputElement)) return
142+
143+
const files = input.files
144+
if (!files || files.length === 0) return
145+
146+
container.attach(files)
147+
input.value = ''
148+
}

0 commit comments

Comments
 (0)