Skip to content

Commit 5b75835

Browse files
committed
fix(FileUpload): accept any subtype
The accept prop did not work with image/* etc.
1 parent 39bafe9 commit 5b75835

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/runtime/composables/useFileUpload.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,31 @@ export function useFileUpload(options: UseFileUploadOptions) {
6767
}
6868

6969
onMounted(() => {
70-
const { isOverDropZone } = dropzone
71-
? useDropZone(dropzoneRef, { dataTypes: dataTypes.value, onDrop })
72-
: { isOverDropZone: ref(false) }
70+
const { isOverDropZone } = useDropZone(dropzoneRef, {
71+
dataTypes: (types) => {
72+
if (dataTypes.value === undefined || accept === '*') {
73+
return true
74+
}
75+
76+
return types.some((type) => {
77+
return dataTypes.value?.some((acceptedType) => {
78+
if (acceptedType.endsWith('/*')) {
79+
const base = acceptedType.slice(0, acceptedType.indexOf('/'))
80+
return type.startsWith(base + '/')
81+
} else {
82+
return type === acceptedType
83+
}
84+
})
85+
})
86+
}, onDrop: (files, event) => {
87+
if (!dropzone) {
88+
event.preventDefault()
89+
return
90+
}
91+
92+
onDrop(files)
93+
}
94+
})
7395

7496
watch(isOverDropZone, (value) => {
7597
isDragging.value = value

0 commit comments

Comments
 (0)