@uppy/components: inherit restrictions from @uppy/core (#6014)

Closes #5970

AI disclosure: codex made the initial implementation

---------

Co-authored-by: Mikael Finstad <finstaden@gmail.com>
This commit is contained in:
Merlijn Vos 2025-10-23 10:10:45 +02:00 committed by GitHub
parent 55e926c347
commit 26bf726412
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 13 deletions

View file

@ -0,0 +1,5 @@
---
"@uppy/components": patch
---
Dropzone and FileInput inherit restrictions from @uppy/core

View file

@ -21,6 +21,7 @@ export type DropzoneReturn<DragEventType, ChangeEventType> = {
id: string
type: 'file'
multiple: boolean
accept?: string
onChange: (event: ChangeEventType) => void
}
}
@ -117,11 +118,17 @@ export function createDropzone<
onClick: handleClick,
onKeyPress: handleKeyPress,
}),
getInputProps: () => ({
id: fileInputId,
type: 'file',
multiple: true,
onChange: handleFileInputChange,
}),
getInputProps: () => {
const { restrictions } = ctx.uppy.opts
const accept = restrictions.allowedFileTypes?.join(', ')
return {
id: fileInputId,
type: 'file' as const,
multiple: restrictions.maxNumberOfFiles !== 1,
accept,
onChange: handleFileInputChange,
}
},
}
}

View file

@ -49,13 +49,23 @@ export function createFileInput<EventType extends Event>(
}
return {
getInputProps: () => ({
id: fileInputId,
type: 'file',
multiple: props.multiple ?? true,
accept: props.accept,
onChange: handleFileInputChange,
}),
getInputProps: () => {
const { restrictions } = ctx.uppy.opts
const { allowedFileTypes, maxNumberOfFiles } = restrictions
let accept = props.accept
accept ??= allowedFileTypes?.join(', ')
let multiple = props.multiple
multiple ??= maxNumberOfFiles !== 1
return {
id: fileInputId,
type: 'file' as const,
multiple,
accept,
onChange: handleFileInputChange,
}
},
getButtonProps: () => ({
type: 'button',
onClick: handleClick,