Inside of a Form
The FileDropzone
component is intended to be a wrapper around a FileInput
component to extend functionality to include drag and drop.
The preview has been updated.
Single File Upload
When multiple file upload is not enabled (on FileInput), add the FileTile
as a child of the FileDropzone
which applies specific styling for single file upload. When multiple files are dropped on the dropzone and it's not enabled, then the dropzone will show an error on drag and only pass the first file to the input's onChange
event.
The preview has been updated.
Disabled
To disable the FileDropzone
, add the disabled
prop on the FileInput
.
The preview has been updated.
Validation
You may want to validate files when the user adds files to the dropzone such as accepted file types, max file size and total number of files. We recommend that you do this during the onChange event of the FileInput. An example of some common file validation has been provided below, feel free to copy/paste and update as necessary.
FileInput accept prop
Per the validation code snippet below, we have provided an example of sharing the same values in the FileInput
accept
prop for the accepted file validation. Note that this method is recommended but you must only use individual mime types unless you update the validation function to handle wildcards. See a full implementation in the next section.
Full Implementation
This is an example of how you might implement the FileDropzone
with FileTiles
and file validation. Feel free to take this and tweak as necessary for your use case.
The preview has been updated.