Overview
The DropZone component provides a complete file upload solution with drag-and-drop support, file validation, upload progress tracking, automatic preview generation, and extensive customization options. It’s built with composition in mind and includes both headless hooks and pre-styled components.Use Cases
- Image and document uploads
- Multi-file upload forms
- Profile picture uploads
- Media library management
- File attachment systems
- Drag-and-drop file interfaces
Installation
The DropZone component is included with the UI package:Basic Usage
Component Parts
DropZone.Root
The root provider that manages drop zone state and behavior.File Validation
File Validation
accept- Accepted file types (MIME types or extensions)maxFiles- Maximum number of files allowedmaxSize- Maximum file size in bytesminSize- Minimum file size in bytesvalidator- Custom validation function
Upload Behavior
Upload Behavior
multiple- Allow multiple file selection (default:false)disabled- Disable the drop zoneinitialFiles- Pre-populate with existing filesdisablePreviewGenForNonImageFiles- Only generate previews for images (default:true)
Callbacks
Callbacks
onFilesChange- Called when files changeonUpload- Handle file upload with progress trackingonValidationError- Called for each validation erroronValidationSuccess- Called after successful validation
Advanced
Advanced
disableInternalStateSubscription- Disable automatic state updatesdisableFilePickerOpenOnAreaClick- Prevent area clicks from opening file pickerunstyled- Disable default styling
DropZone.Area
Combines Container and Input with Context for a complete drop area.DropZone.Container
The drop target container.data-drag-over- Present when dragging overdata-invalid- Present when files are invalid
DropZone.Input
The hidden file input element.DropZone.Trigger
Button to open the file picker.DropZone.FileList
Container for the list of selected files.renderMode-"per-item"renders children for each file,"manual-list"gives full controlforceMount- Keep mounted even when emptyas- Change rendered element (default:"ul")
DropZone.FileItem
Wrapper for individual file items.DropZone.FileItemPreview
File preview with automatic type detection.- Image previews for image files
- Appropriate icons for video, audio, code, archives, etc.
DropZone.FileItemMetadata
Displays file name, size, and errors.- File name
- File size (formatted)
- Error message (if any)
DropZone.FileItemProgress
Upload progress indicator.DropZone.FileItemDelete
Button to remove a file.DropZone.FileClear
Button to clear all files.Examples
Image Upload with Preview
Compact File Upload
Custom Validation
Circular Progress Indicator
File State
Each file has the following state:Validation
The DropZone supports comprehensive file validation:file-invalid-typetoo-many-filesfile-too-largefile-too-smallupload-error(from onUpload)
File previews are automatically generated for images. For other file types, appropriate icons are displayed based on the file extension and MIME type.
Styling
All parts include data attributes for styling:Accessibility
- File input is properly associated with the drop area
- Keyboard navigation supported via trigger button
- ARIA labels for delete and clear buttons
- Error messages are announced
- Supports paste events for file upload