Skip to main content

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.
Key Props:
  • accept - Accepted file types (MIME types or extensions)
  • maxFiles - Maximum number of files allowed
  • maxSize - Maximum file size in bytes
  • minSize - Minimum file size in bytes
  • validator - Custom validation function
  • multiple - Allow multiple file selection (default: false)
  • disabled - Disable the drop zone
  • initialFiles - Pre-populate with existing files
  • disablePreviewGenForNonImageFiles - Only generate previews for images (default: true)
  • onFilesChange - Called when files change
  • onUpload - Handle file upload with progress tracking
  • onValidationError - Called for each validation error
  • onValidationSuccess - Called after successful validation
  • disableInternalStateSubscription - Disable automatic state updates
  • disableFilePickerOpenOnAreaClick - Prevent area clicks from opening file picker
  • unstyled - Disable default styling

DropZone.Area

Combines Container and Input with Context for a complete drop area.

DropZone.Container

The drop target container.
Data Attributes:
  • data-drag-over - Present when dragging over
  • data-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.
Props:
  • renderMode - "per-item" renders children for each file, "manual-list" gives full control
  • forceMount - Keep mounted even when empty
  • as - Change rendered element (default: "ul")

DropZone.FileItem

Wrapper for individual file items.

DropZone.FileItemPreview

File preview with automatic type detection.
Automatically shows:
  • Image previews for image files
  • Appropriate icons for video, audio, code, archives, etc.
Custom Previews:

DropZone.FileItemMetadata

Displays file name, size, and errors.
Default rendering includes:
  • 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:
Built-in validation error codes:
  • file-invalid-type
  • too-many-files
  • file-too-large
  • file-too-small
  • upload-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.
Don’t forget to revoke object URLs when components unmount to prevent memory leaks. The DropZone handles this automatically.

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

API Reference

For detailed prop types and advanced usage, see the DropZone API Reference.