Skip to main content
Tw Twintrinsic
  • Getting Started
  • Components
  • Theming
  • Completion
Examples
Data Dashboard Game Map
Core
App
Layout
Accordion AccordionItem Card Container Panel Separator Sidebar Splitter
Navigation
AppHeader BottomBar Breadcrumb BreadcrumbItem Menu MenuItem Tabs Tab TabList TabPanel TreeMenu
Data Display
Avatar AvatarGroup Badge Carousel CarouselItem Chip ChipGroup CodeBlock CodeBlockSpeed CodeEditor DataTable Map Progress Skeleton Table TableBody TableCell TableHead TableHeader TableRow Tag TagGroup Timeline TimelineItem Tooltip Tree TreeNode
Metrics
DonutChart PieChart LineChart BarChart HorizontalBarChart AreaChart StatsCard MetricGrid KPICard GaugeChart ProgressMetric MetricTrend
Form
AutoComplete Button ButtonGroup Calendar Checkbox ColorPicker Combobox Dropdown FileUpload FloatLabel Form FormField Input InputSwitch InvalidState Knob ListInput Listbox NumberInput Radio RadioGroup Rating Select SelectGroup Slider Switch TextInput Textarea
Feedback
Modal Stepper StepperStep Toast
Utility
Icon Lazy LazyPanel Masonry ThemeToggle

FileUpload

The FileUpload component provides a modern interface for uploading files with drag-and-drop support, file validation, and progress tracking. It's designed to be user-friendly and accessible.

Examples

Basic File Upload

Drop files here or click to browse

svelte
<FileUpload 
  dropzoneLabel="Drop files here or click to browse"
  browseLabel="Select Files"
  onchange={(e) => console.log(e.detail.files)}
/>

Image Upload

Drop images here or click to browse

Maximum size: 2 MB

Accepted types: image/*

svelte
<FileUpload 
  accept="image/*"
  dropzoneLabel="Drop images here or click to browse"
  browseLabel="Select Images"
  maxSize={2097152} // 2MB
  onchange={(e) => console.log(e.detail.files)}
/>

Document Upload

Drop documents here or click to browse

Accepted types: .pdf,.doc,.docx,.txt

svelte
<FileUpload 
  accept=".pdf,.doc,.docx,.txt"
  dropzoneLabel="Drop documents here or click to browse"
  browseLabel="Select Documents"
  onchange={(e) => console.log(e.detail.files)}
/>

Single File Upload

Drop a file here or click to browse

svelte
<FileUpload 
  multiple={false}
  dropzoneLabel="Drop a file here or click to browse"
  browseLabel="Select File"
  onchange={(e) => console.log(e.detail.files)}
/>

With File Validation

Drop up to 3 images (max 1MB each)

Maximum 3 files

Maximum size: 1 MB

Accepted types: image/*

svelte
<FileUpload 
  accept="image/*"
  maxFiles={3}
  maxSize={1048576} // 1MB
  dropzoneLabel="Drop up to 3 images (max 1MB each)"
  browseLabel="Select Images"
  onerror={(e) => console.log(e.detail.errors)}
/>

Disabled State

Upload disabled

svelte
<FileUpload 
  disabled
  dropzoneLabel="Upload disabled"
  browseLabel="Cannot select files"
/>

Custom Styling

Drop files here or click to browse

svelte
<FileUpload 
  class="border-2 border-dashed border-primary-500 dark:border-primary-400 rounded-xl p-8"
  dropzoneLabel="Drop files here or click to browse"
  browseLabel="Select Files"
/>

With Auto Upload

Drop files here or click to browse

svelte
<FileUpload 
  dropzoneLabel="Drop files here or click to browse"
  browseLabel="Select Files"
  autoUpload
  uploadUrl="/api/upload"
  onsuccess={(e) => console.log('Upload successful', e.detail)}
  onerror={(e) => console.log('Upload failed', e.detail.errors)}
  onprogress={(e) => console.log('Progress:', e.detail.progress)}
/>

Props

PropTypeDefaultDescription
acceptstring""File types to accept (e.g., "image/*", ".pdf,.doc")
multiplebooleantrueWhether to allow multiple file selection
maxFilesnumber5Maximum number of files allowed
maxSizenumberundefinedMaximum file size in bytes
disabledbooleanfalseWhether the upload is disabled
showPreviewsbooleantrueWhether to show file previews
autoUploadbooleanfalseWhether to automatically upload files after selection
uploadUrlstringundefinedURL for auto upload functionality
uploadHeadersObjectundefinedCustom headers for upload requests
dropzoneLabelstring"Drag files here or click to browse"Text displayed in the dropzone
browseLabelstring"Browse"Text for the browse button
ariaLabelstring"File upload"ARIA label for accessibility
namestringundefinedName attribute for the file input
idstringrandom UUIDHTML id for accessibility
classstring""Additional CSS classes

Events

EventDetailDescription
change{ files: File[] }Fired when selected files change
error{ errors: Array }Fired when validation or upload errors occur
progress{ progress: number, files: File[] }Fired during upload to indicate progress (0-100)
success{ response: any, files: File[] }Fired when upload completes successfully

Snippets

SnippetPropsDescription
dropzoneNoneCustom dropzone content
previews{ files: File[], removeFile: (index: number) => void }Custom file previews template

Accessibility

The FileUpload component follows accessibility best practices:

  • Uses native <input type="file"> for keyboard and screen reader accessibility
  • Provides clear instructions for drag-and-drop and browse options
  • Uses proper ARIA attributes for the dropzone
  • Provides visual feedback for drag-and-drop interactions
  • Communicates errors and validation issues clearly
  • Shows progress information during uploads

Keyboard Support

KeyFunction
TabMoves focus to the file input
Enter or SpaceWhen focus is on the dropzone, opens the file browser
Enter or SpaceWhen focus is on a file delete button, removes the file