Skip to content

Commit

Permalink
fix(useDropZone): fix file types filter (#3540)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
getname1997 and antfu authored Dec 4, 2023
1 parent 3733b8e commit 8f42a92
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/core/useDropZone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { MaybeRef, Ref } from 'vue-demi'
// eslint-disable-next-line no-restricted-imports
import { ref, shallowRef, unref } from 'vue-demi'
import type { MaybeRefOrGetter } from '@vueuse/shared'
import { isClient } from '@vueuse/shared'
import { isClient, notNullish } from '@vueuse/shared'

// eslint-disable-next-line no-restricted-imports
import { useEventListener } from '@vueuse/core'
Expand Down Expand Up @@ -41,12 +41,16 @@ export function useDropZone(
}

useEventListener<DragEvent>(target, 'dragenter', (event) => {
const types = Array.from(event?.dataTransfer?.items || [])
.map(i => i.kind === 'file' ? i.type : null)
.filter(notNullish)

if (_options.dataTypes && event.dataTransfer) {
const dataTypes = unref(_options.dataTypes)
isDataTypeIncluded = typeof dataTypes === 'function'
? dataTypes(event.dataTransfer!.types)
? dataTypes(types)
: dataTypes
? dataTypes.some(item => event.dataTransfer!.types.includes(item))
? dataTypes.some(item => types.includes(item))
: true
if (!isDataTypeIncluded)
return
Expand Down

0 comments on commit 8f42a92

Please sign in to comment.