- components
- ›
- file upload
- ›
- svelte
File Upload
A component for uploading files with drag-and-drop and browse support.
Custom Content
Supply your own text and icons within the dropzone.
Select file or drag here.
Disabled
Button Only
Clear Files
Use the Provider
pattern to access the clearFiles
method.
- example.png4 bytes
Direction
API Reference
Root
flex flex-col gap-2 w-full data-disabled:disabled
Property | Default | Type |
---|---|---|
name | - | string | undefinedThe name of the underlying file input |
ids | - | Partial<{ 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; }> | undefinedThe ids of the elements. Useful for composition. |
translations | - | IntlTranslations | undefinedThe localized messages to use. |
accept | - | Record<string, string[]> | FileMimeType | FileMimeType[] | undefinedThe accept file types |
disabled | - | boolean | undefinedWhether the file input is disabled |
required | - | boolean | undefinedWhether the file input is required |
allowDrop | true | boolean | undefinedWhether to allow drag and drop in the dropzone element |
maxFileSize | Infinity | number | undefinedThe maximum file size in bytes |
minFileSize | 0 | number | undefinedThe minimum file size in bytes |
maxFiles | 1 | number | undefinedThe maximum number of files |
preventDocumentDrop | true | boolean | undefinedWhether to prevent the drop event on the document |
validate | - | ((file: File, details: FileValidateDetails) => FileError[] | null) | undefinedFunction to validate a file |
defaultAcceptedFiles | - | File[] | undefinedThe default accepted files when rendered. Use when you don't need to control the accepted files of the input. |
acceptedFiles | - | File[] | undefinedThe controlled accepted files |
onFileChange | - | ((details: FileChangeDetails) => void) | undefinedFunction called when the value changes, whether accepted or rejected |
onFileAccept | - | ((details: FileAcceptDetails) => void) | undefinedFunction called when the file is accepted |
onFileReject | - | ((details: FileRejectDetails) => void) | undefinedFunction called when the file is rejected |
capture | - | "user" | "environment" | undefinedThe default camera to use when capturing media |
directory | - | boolean | undefinedWhether to accept directories, only works in webkit browsers |
invalid | - | boolean | undefinedWhether the file input is invalid |
transformFiles | - | ((files: File[]) => Promise<File[]>) | undefinedFunction to transform the accepted files to apply transformations |
locale | "en-US" | string | undefinedThe current locale. Based on the BCP 47 definition. |
dir | "ltr" | "ltr" | "rtl" | undefinedThe document's text/writing direction. |
getRootNode | - | (() => ShadowRoot | Node | Document) | undefinedA root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. |
element | - | Snippet<[HTMLAttributes<"div">]> | undefinedRender the element yourself |
RootProvider
Property | Default | Type |
---|---|---|
value | - | () => FileUploadApi<PropTypes> |
element | - | Snippet<[HTMLAttributes<"div">]> | undefinedRender the element yourself |
RootContext
Property | Default | Type |
---|---|---|
children | - | Snippet<[() => FileUploadApi<PropTypes>]> |
Label
label-text
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"label">]> | undefinedRender the element yourself |
Dropzone
card px-4 py-10 border border-dashed border-surface-200-800 flex flex-col justify-center items-center gap-2 data-dragging:preset-tonal
Property | Default | Type |
---|---|---|
disableClick | - | boolean | undefinedWhether to disable the click event on the dropzone |
element | - | Snippet<[HTMLAttributes<"div">]> | undefinedRender the element yourself |
Trigger
btn preset-filled
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"button">]> | undefinedRender the element yourself |
HiddenInput
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"input">]> | undefinedRender the element yourself |
ItemGroup
flex flex-col gap-2
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"ul">]> | undefinedRender the element yourself |
Item
grid grid-cols-[auto_1fr_auto] gap-4 items-center preset-tonal px-4 py-2 rounded
Property | Default | Type |
---|---|---|
file | - | File |
type | - | ItemType | undefined |
element | - | Snippet<[HTMLAttributes<"li">]> | undefinedRender the element yourself |
ItemName
text-sm
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"div">]> | undefinedRender the element yourself |
ItemSizeText
text-xs opacity-60
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"div">]> | undefinedRender the element yourself |
ItemDeleteTrigger
btn-icon
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"button">]> | undefinedRender the element yourself |