File Upload
Drag-and-drop file picker that lists the chosen files.
<arc-file-upload>Overview
FileUpload is a dashed dropzone for choosing files. People drop files on it, or click it (or press Enter or Space on it) to open the native file picker. Chosen files appear in a list below with their name, size in B, KB, MB or GB, and a remove button. It only selects files: uploading them, and showing progress, is up to you.
accept is passed to the native picker, which filters what can be chosen there. Dropped files aren't checked against it, so check the type yourself before uploading. max-size is in bytes. Larger files are left out, with an error under the dropzone naming them, and 0 (the default) means no limit. The dropzone shows both limits as hints.
With multiple, each drop or browse adds to the list. Without it, a new file replaces the old one, and only the first of several dropped files is kept. arc-change fires with the whole file array whenever the list changes, and removing a file also fires arc-remove with that file and its index. It isn't a form control, so the files don't submit with a form. Read them from arc-change.
Guidelines
Do
- Set `accept` to say which file types you want, such as `accept="image/*"`
- Set `max-size` so oversized files are stopped before they reach your server
- Set `multiple` when people need to add several files, as for a photo gallery
- Give it enough width for the hint text and the file names
Don't
- Don't rely on `accept` to block other file types. It only filters the native picker
- Don't set `max-size` to 0 and expect a limit. 0 means no limit
Features
- The border turns the accent color and the background tints while files are dragged over it
- `disabled` lowers the opacity and blocks clicks, drops and the keyboard
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-file-upload id="uploader" accept="image/*" multiple></arc-file-upload>
<script>
const uploader = document.getElementById('uploader');
uploader.addEventListener('arc-change', (e) => {
const files = e.detail.value;
files.forEach(file => {
console.log(file.name, file.size, file.type);
});
// Example: upload via FormData
const form = new FormData();
files.forEach(f => form.append('files', f));
fetch('/api/upload', { method: 'POST', body: form });
});
uploader.addEventListener('arc-remove', (e) => {
console.log('Removed:', e.detail.value.name);
});
</script>import { FileUpload } from '@arclux/arc-ui-react';
function Upload() {
function handleChange(e) {
const files = e.detail.value;
const form = new FormData();
files.forEach(f => form.append('files', f));
fetch('/api/upload', { method: 'POST', body: form });
}
return (
<FileUpload
accept="image/*"
multiple
onArcChange={handleChange}
/>
);
}<script setup>
import { FileUpload } from '@arclux/arc-ui-vue';
</script>
<template>
<FileUpload accept="image/*" multiple />
</template><script>
import { FileUpload } from '@arclux/arc-ui-svelte';
</script>
<FileUpload accept="image/*" multiple />import { Component } from '@angular/core';
import { FileUpload } from '@arclux/arc-ui-angular';
@Component({
imports: [FileUpload],
template: `
<arc-file-upload accept="image/*" multiple></arc-file-upload>
`,
})
export class MyComponent {}import { FileUpload } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<FileUpload accept="image/*" multiple />
);
}import { FileUpload } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<FileUpload accept="image/*" multiple />
);
}API
acceptstring''- Comma-separated list of accepted file types, passed directly to the native file input accept attribute. Examples: "image/*", ".pdf,.docx", "audio/mp3".
multiplebooleanfalse- When true, allows selecting multiple files. Each drop or browse interaction appends to the existing file list rather than replacing it.
maxSizenumber0- Maximum file size in bytes. Files exceeding this limit are rejected with an inline error message. Set to 0 for no limit.
disabledbooleanfalse- Disables the dropzone, preventing drag-and-drop and click interactions. Reduces opacity to 0.4.
Events
arc-change- Fired when files are added or dropped
arc-remove- Fired when a file is removed from the list
See also
- InputText field with a built-in label, placeholder and validation states. Set `multiline` for a textarea.
- ButtonAction button with three variants for action hierarchy and prefix and suffix slots for icons. For links, slot a real anchor, which works before JavaScript loads.
- ProgressA progress bar or spinner for long-running work, with or without a known percentage.