1. framework components
  2. file upload

File Upload

File upload dropzone and input patterns for selecting files.

Select file or drag here.

Disabled

Set the disabled prop to enable the disabled state.

Button Only

Replace the interface with a simple “browse” button.

Direction

Set the text direction (ltr or rtl) using the dir prop.

Anatomy

Here’s an overview of how the FileUpload component is structured in code:

svelte
<script lang="ts">
	import { FileUpload } from '@skeletonlabs/skeleton-svelte';
</script>

<FileUpload>
	<FileUpload.Dropzone>
		<FileUpload.Trigger />
		<FileUpload.HiddenInput />
	</FileUpload.Dropzone>
	<FileUpload.ItemGroup>
		<FileUpload.Item>
			<FileUpload.ItemName />
			<FileUpload.ItemSizeText />
			<FileUpload.ItemDeleteTrigger />
		</FileUpload.Item>
	</FileUpload.ItemGroup>
	<FileUpload.ClearTrigger />
</FileUpload>

API Reference

Root

PropDefaultType
namestring | undefined

The name of the underlying file input

idsPartial<{ root: string; dropzone: string; hiddenInput: string; trigger: string; label: string; item: (id: string) => string; itemName: (id: string) => string; itemSizeText: (id: string) => string; itemPreview: (id: string) => string; }> | undefined

The ids of the elements. Useful for composition.

translationsIntlTranslations | undefined

The localized messages to use.

acceptRecord<string, string[]> | FileMimeType | FileMimeType[] | undefined

The accept file types

disabledboolean | undefined

Whether the file input is disabled

requiredboolean | undefined

Whether the file input is required

allowDroptrueboolean | undefined

Whether to allow drag and drop in the dropzone element

maxFileSizeInfinitynumber | undefined

The maximum file size in bytes

minFileSize0number | undefined

The minimum file size in bytes

maxFiles1number | undefined

The maximum number of files

preventDocumentDroptrueboolean | undefined

Whether to prevent the drop event on the document

validate((file: File, details: FileValidateDetails) => FileError[] | null) | undefined

Function to validate a file

defaultAcceptedFilesFile[] | undefined

The default accepted files when rendered. Use when you don't need to control the accepted files of the input.

acceptedFilesFile[] | undefined

The controlled accepted files

onFileChange((details: FileChangeDetails) => void) | undefined

Function called when the value changes, whether accepted or rejected

onFileAccept((details: FileAcceptDetails) => void) | undefined

Function called when the file is accepted

onFileReject((details: FileRejectDetails) => void) | undefined

Function called when the file is rejected

capture"user" | "environment" | undefined

The default camera to use when capturing media

directoryboolean | undefined

Whether to accept directories, only works in webkit browsers

invalidboolean | undefined

Whether the file input is invalid

transformFiles((files: File[]) => Promise<File[]>) | undefined

Function to transform the accepted files to apply transformations

locale"en-US"string | undefined

The current locale. Based on the BCP 47 definition.

dir"ltr""ltr" | "rtl" | undefined

The document's text/writing direction.

getRootNode(() => ShadowRoot | Node | Document) | undefined

A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron.

elementSnippet<[HTMLAttributes<"div">]> | undefined

Render the element yourself

Provider

PropDefaultType
value() => FileUploadApi<PropTypes>

elementSnippet<[HTMLAttributes<"div">]> | undefined

Render the element yourself

Context

PropDefaultType
childrenSnippet<[any]>

Label

PropDefaultType
elementSnippet<[HTMLAttributes<"label">]> | undefined

Render the element yourself

Dropzone

PropDefaultType
disableClickboolean | undefined

Whether to disable the click event on the dropzone

elementSnippet<[HTMLAttributes<"div">]> | undefined

Render the element yourself

Trigger

PropDefaultType
elementSnippet<[HTMLAttributes<"button">]> | undefined

Render the element yourself

ClearTrigger

PropDefaultType
elementSnippet<[HTMLAttributes<"button">]> | undefined

Render the element yourself

HiddenInput

PropDefaultType
elementSnippet<[HTMLAttributes<"input">]> | undefined

Render the element yourself

ItemGroup

PropDefaultType
elementSnippet<[HTMLAttributes<"ul">]> | undefined

Render the element yourself

Item

PropDefaultType
fileFile

typeItemType | undefined

elementSnippet<[HTMLAttributes<"li">]> | undefined

Render the element yourself

ItemName

PropDefaultType
elementSnippet<[HTMLAttributes<"div">]> | undefined

Render the element yourself

ItemSizeText

PropDefaultType
elementSnippet<[HTMLAttributes<"div">]> | undefined

Render the element yourself

ItemDeleteTrigger

PropDefaultType
elementSnippet<[HTMLAttributes<"button">]> | undefined

Render the element yourself

View page on GitHub