File Upload
The File Upload component allows users to select and upload files via click-to-browse or drag & drop. It supports three layout variants — a general-purpose drag zone, an image-specific uploader, and a profile photo uploader — along with built-in validation for file size, file type, and maximum file count. Upload progress is simulated with a visual progress bar, and files can be cancelled or retried on failure.
The component wraps react-dropzone for drag & drop support and accepts props for configuration and an onFileUpload callback.
The component implements drag & drop natively using dragover, dragleave, and drop events. It accepts equivalent props and emits events for file lifecycle changes.
Loading Code Block...Full example
Section titled “Full example”The default configuration renders a drag & drop zone that accepts a single file of any type, with a 5 MB size limit.
Loading Code Block...Variants
Section titled “Variants”Three layout variants are available via the variant prop.
| Variant | Description |
|---|---|
drag | General-purpose drop zone with file list, progress bars, and status icons. |
image | Optimised for image uploads with a visual preview of the selected image. |
profile | Circular avatar-style uploader for profile photos. |
Disabled
Section titled “Disabled”Set disabled to prevent file selection and drag & drop interactions. The component receives reduced opacity and cursor-not-allowed.
File type restrictions
Section titled “File type restrictions”Use the accept prop to restrict which file types can be uploaded. The component provides predefined categories that map to MIME types and extensions:
| Accept value | Allowed extensions |
|---|---|
"all" | Any file type |
"image" | .jpg, .jpeg, .svg, .png, .gif, .webp |
"document" | .doc, .docx, .xls, .xlsx, .ppt, .pptx |
"pdf" | .pdf |
"video" | .mp4, .mov, .avi, .mkv, .webm |
Multiple files
Section titled “Multiple files”Enable multi-file uploads with the multiple prop. Use maxFiles to cap the number of files allowed.
Loading Code Block...Upload lifecycle
Section titled “Upload lifecycle”The drag variant includes a full upload lifecycle with visual feedback:
1. User selects or drops files ↓2. Validation (file size, file type, max count) ↓ ┌─── PASS ───┐ ┌─── FAIL ───┐ ↓ ↓ ↓ ↓3. Progress bar 4. Error state animates (red border, ↓ retry icon) ↓ ↓5. Completed 6. Retry or (green ✓) Remove- Progress: Simulated upload progress with a progress bar and file size indicator.
- Success: Green border, check icon, “Completed” label.
- Error: Red border, alert icon, error message, with retry and delete options.
- Cancel: In-progress uploads can be cancelled by clicking the close icon.
FileUpload
Section titled “FileUpload ”Vue Events
| Event | Default | Type | Description |
|---|---|---|---|
| file-selected | - | (file: File) => void | Emitted once per accepted file as it is selected by the user. Fires on all variants. |
| upload-success | - | (response: File[]) => void | Emitted when a file upload completes successfully. Drag fires per file at 100% progress; image fires once per batch when all files succeed; profile fires once per accepted file. |
| upload-error | - | (error: unknown) => void | Emitted when validation fails (size, type, max-files) or when a simulated upload errors. |
| error | - | (error: unknown) => void | Re-emitted by `Upload.vue` alongside every `upload-error` with the same payload. Provided for consumers that prefer the shorter event name. |
| upload-progress | - | (progress: number) => void | Emitted during upload with the current progress percentage (0–100). Only the 'drag' variant emits this — 'image' and 'profile' do not. |
| update:modelValue | - | (files: File[]) => void | Supports v-model for two-way binding. Always emits a File array: cumulative valid files for 'drag', successfully uploaded files for 'image', `[selectedFile]` (or `[]` on remove) for 'profile'. |
Accessibility
Section titled “Accessibility”- The file input is hidden visually and triggered programmatically by clicking the drop zone label.
- The drop zone is keyboard-accessible — users can tab to it and press Enter or Space to open the file picker.
- Error messages are displayed inline with alert icons for visual clarity.
- When
disabled,pointer-events: noneprevents accidental interaction. - File status (uploading, completed, error) is communicated with both icons and text labels for users who cannot perceive colour alone.