Basic usage
Filedrop wraps any content in a drop area. Dropped files are passed to upload one by one, and
the area also contains a FileInput, so users can click to browse.
import {Filedrop, ACCEPTED_IMAGE_TYPES} from '@pleo-io/telescope'
const ReceiptDropzone = ({onUpload}: {onUpload: (file: File) => void}) => (
<Filedrop upload={onUpload} accept={ACCEPTED_IMAGE_TYPES} name="receipt">
Drop a receipt here or browse your files
</Filedrop>
)Validation
Dropped files are checked before upload is called:
- Size: files larger than
maxFileSizeAllowed(25 MB by default) show a negative toast and are not uploaded. - Type: when
acceptis set, files with another MIME type show a negative toast. - Count: with
multipleFileSelectionandmaximumNumberOfFiles, dropping more files than allowed shows a negative toast and uploads nothing.
The toasts are shown with useToaster, so the page needs a ToasterProvider and a Toaster in the
tree. Use ACCEPTED_IMAGE_TYPES for the common image and PDF formats.
Localisation
The toast messages come from the TelescopeProvider translations under FileInput, the same keys
as file input.
Accessibility
- The drop area is a
labelaround the nested file input. The nested file input stays in the tab order, so keyboard users can open the file dialog with Enter or Space. - Pass
aria-describedbyto connect the drop area to hint or error text, andisRequiredorisInvalidto reflect the form state. - Drag handlers only enhance pointer users. Always keep the browse option available.
API reference
| Prop | Type | Default |
|---|---|---|
acceptNo description available | enumstring | undefined | |
aria-describedbyNo description available | enumstring | undefined | |
classNameNo description available | enumstring | undefined | |
isInvalidNo description available | boolean | |
isRequiredNo description available | boolean | |
maxFileSizeAllowedNo description available | enumnumber | undefined | |
maximumNumberOfFilesNo description available | enumnumber | undefined | |
multipleFileSelectionNo description available | boolean | |
nameNo description available | enumstring | undefined | |
onDragLeaveNo description available | enum(e: DragEvent<Element>) => void | |
onDragOverNo description available | enum(e: DragEvent<Element>) => void | |
onDropNo description available | enum(e: DragEvent<Element>) => void | |
onUploadButtonClickNo description available | enum() => void | |
upload (required)No description available | function(file: File) => void |