No results found

File Upload

A drag and drop interface for uploading files with support for filtering and multiple selections.

Drag and drop files here or

Features

  • Drag and drop file upload support
  • Multiple file selection option
  • File type filtering/validation
  • Visual drag state feedback
  • Button trigger for system file dialog
  • Disabled state handling
  • File change notifications via callbacks
  • Copy effect indicators during drag
  • Cross-browser drag and drop compatibility
  • Compound component architecture

Anatomy

PartDescription
<FileUpload.Root>Root component for file upload functionality Provides context and state management for child components
<FileUpload.Dropzone>Component that handles drag and drop file upload functionality
<FileUpload.Input>Hidden file input component that handles file selection via system dialog
<FileUpload.Trigger>Trigger component that opens the file selection dialog Acts as a styled button that triggers the hidden file input

Examples

Basic Usage

The most basic implementation allows users to upload files through drag and drop or button click.

Visual Features

The file upload can be styled to match your application's design system.

Advanced Usage

Multiple File Upload

Enable multiple file selection and handle batch uploads.

Disabled State

Control the interactive state of the upload component.

Component State

Using Component State

The File Upload component's state can be controlled through several props on the FileUpload.Root component:

  1. Multiple File Selection
  1. File Type Filtering
  1. Disabled State

State Interactions

The component provides a callback to handle file changes:

  1. File Change Handler
<FileUpload.Root
  onFilesChange$={(files) => {
    // files is an array of FileInfo objects
    files.forEach(file => {
      console.log(file.name, file.size, file.type);
    });
  }}
>

The onFilesChange$ prop receives an array of FileInfo objects containing:

  1. Drag State The component automatically manages drag states:
  1. Processing State

Based on the provided examples and API documentation, I'll document the configuration options for the File Upload component.

Core Configuration

File Selection Mode

The File Upload component supports both single and multiple file selection modes through the multiple prop on FileUpload.Root. As shown in the hero example above, by default, the component operates in single file mode. To enable multiple file selection, add the multiple prop to FileUpload.Root.

The multiple prop is false by default, allowing only single file selection.

File Type Filtering

The component supports file type filtering through the accept prop on FileUpload.Root. This allows you to restrict which file types users can select. As shown in the hero example above, you can use MIME types or file extensions to filter files:

Common accept values:

  • "image/*" - All image types
  • ".pdf,.doc,.docx" - Specific file extensions
  • "video/*,audio/*" - Multiple MIME types

Disabled State

The File Upload component can be disabled entirely using the disabled prop on FileUpload.Root. When disabled:

Advanced Configuration

File Change Handling

The component provides detailed file information through the onFilesChange$ callback prop on FileUpload.Root. The callback receives an array of FileInfo objects with the following structure:

interface FileInfo {
  name: string;
  size: number;
  type: string;
  lastModified: number;
  file: NoSerialize<File>;
}

The file property is wrapped in NoSerialize to prevent serialization issues in Qwik's resumability model.

Drag and Drop Configuration

The component automatically handles drag and drop events and provides visual feedback through data attributes:

interface DropzoneAttributes {
  "data-dragging": string | undefined;  // Present when files are being dragged
  "data-disabled": string | undefined;  // Present when dropzone is disabled
}

These attributes can be used for styling and state management in more complex implementations.

API Reference

File Upload Dropzone

Inherits from: <div />

Props

PropTypeDefaultDescription
namestring-
sizenumber-
typestring-
lastModifiednumber-
fileFile-
fileInfosPublicRawFileInfo[]-

Data Attributes

AttributeDescription
data-file-upload-dropzone
data-draggingIndicates whether files are currently being dragged over the dropzone
data-disabledIndicates whether the dropzone is currently disabled

File Upload Root

Inherits from: <div />

Data Attributes

AttributeDescription
data-file-upload-root
data-disabled

File Upload Input

Inherits from: <input />

Data Attributes

AttributeDescription
data-file-upload-inputThe hidden file input element that handles native file selection

File Upload Trigger

Inherits from: <button />

Data Attributes

AttributeDescription
data-file-upload-triggerThe button element that triggers the file selection dialog

Accessibility

Keyboard Interactions

KeyDescription
SpaceWhen focus is on the trigger button, opens the file selection dialog
EnterWhen focus is on the trigger button, opens the file selection dialog
TabMoves focus to the trigger button or other interactive elements within the component
EscapeWhen the file selection dialog is open, closes the dialog without selecting files