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