Skip to content

Commit aee846c

Browse files
authored
feat(useDropZone): add checkValidity function (#5169)
1 parent f74a68d commit aee846c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/core/useDropZone/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export interface UseDropZoneOptions {
1616
* Also can be a function to check the data types.
1717
*/
1818
dataTypes?: MaybeRef<readonly string[]> | ((types: readonly string[]) => boolean)
19+
/**
20+
* Similar to dataTypes, but exposes the DataTransferItemList for custom validation.
21+
* If provided, this function takes precedence over dataTypes.
22+
*/
23+
checkValidity?: (items: DataTransferItemList) => boolean
1924
onDrop?: (files: File[] | null, event: DragEvent) => void
2025
onEnter?: (files: File[] | null, event: DragEvent) => void
2126
onLeave?: (files: File[] | null, event: DragEvent) => void
@@ -67,6 +72,10 @@ export function useDropZone(
6772
}
6873

6974
const checkValidity = (items: DataTransferItemList) => {
75+
if (_options.checkValidity) {
76+
return _options.checkValidity(items)
77+
}
78+
7079
const types = Array.from(items ?? []).map(item => item.type)
7180

7281
const dataTypesValid = checkDataTypes(types)

0 commit comments

Comments
 (0)