WlFileUpload
Selection
Local demo: add images, PDF or TXT files up to 1 MiB. Advance progress, show an error and retry. Files are not sent to a server.
Files selected: 0
Full example
<script setup lang="ts">
import { WlButton, WlFileUpload } from "legato-ui";
import { ref } from "vue";
const files = ref<File[]>([]);
interface FileState { progress: number; status: "pending" | "uploading" | "success" | "error"; message?: string }
const states = ref(new Map<File, FileState>());
function fileState(file: File): FileState {
return states.value.get(file) ?? { progress: 0, status: "pending" };
}
function advance(): void {
for (const file of files.value) {
const previous = fileState(file);
if (previous.status === "error") continue;
const progress = Math.min(100, previous.progress + 25);
states.value.set(file, { progress, status: progress === 100 ? "success" : "uploading" });
}
}
function fail(): void {
const file = files.value[0];
if (file) states.value.set(file, { ...fileState(file), status: "error", message: "Local example error. Retry to start again." });
}
function retry(file: File): void {
states.value.set(file, { progress: 0, status: "pending" });
}
function clear(): void {
files.value = [];
states.value.clear();
}
</script>
<template>
<div class="wl-stack" data-space="md">
<p class="wl-text-small">{{ "Local demo: add images, PDF or TXT files up to 1 MiB. Advance progress, show an error and retry. Files are not sent to a server." }}</p>
<WlFileUpload
v-model="files"
accept="image/*,.pdf,.txt"
:max-files="3"
:max-size="1048576"
preview
:file-state="fileState"
>
<template #row="{ file, size, previewUrl, state, remove }">
<img
v-if="previewUrl"
class="wl-upload__preview"
:src="previewUrl"
alt=""
/>
<span class="wl-upload__name">{{ file.name }}</span>
<span class="wl-upload__size">{{ size }}</span>
<progress
class="wl-upload__progress"
:value="state?.progress ?? 0"
max="100"
:aria-label="'File progress:' + ' ' + file.name"
></progress>
<span v-if="state?.message" class="wl-upload__message">{{ state.message }}</span>
<WlButton
v-if="state?.status === 'error'"
size="sm"
variant="ghost"
@click="retry(file)"
>{{ "Retry" }}</WlButton>
<WlButton
size="sm"
variant="ghost"
:aria-label="'Remove' + ' ' + file.name"
@click="remove"
>{{ "Delete" }}</WlButton>
</template>
</WlFileUpload>
<div class="wl-inline" data-space="sm">
<WlButton size="sm" :disabled="!files.length" @click="advance">{{ "Advance demo progress" }}</WlButton>
<WlButton
size="sm"
:disabled="!files.length"
variant="ghost"
@click="fail"
>{{ "Show error" }}</WlButton>
<WlButton size="sm" variant="ghost" @click="clear">{{ "Clear lists and errors" }}</WlButton>
</div>
<p class="wl-text-small" role="status">{{ "Files selected:" }} {{ files.length }}</p>
</div>
</template>Limits
Local demo: add images, PDF or TXT files up to 1 MiB. Advance progress, show an error and retry. Files are not sent to a server.
Files selected: 0
Full example
<script setup lang="ts">
import { WlButton, WlFileUpload } from "legato-ui";
import { ref } from "vue";
const files = ref<File[]>([]);
interface FileState { progress: number; status: "pending" | "uploading" | "success" | "error"; message?: string }
const states = ref(new Map<File, FileState>());
function fileState(file: File): FileState {
return states.value.get(file) ?? { progress: 0, status: "pending" };
}
function advance(): void {
for (const file of files.value) {
const previous = fileState(file);
if (previous.status === "error") continue;
const progress = Math.min(100, previous.progress + 25);
states.value.set(file, { progress, status: progress === 100 ? "success" : "uploading" });
}
}
function fail(): void {
const file = files.value[0];
if (file) states.value.set(file, { ...fileState(file), status: "error", message: "Local example error. Retry to start again." });
}
function retry(file: File): void {
states.value.set(file, { progress: 0, status: "pending" });
}
function clear(): void {
files.value = [];
states.value.clear();
}
</script>
<template>
<div class="wl-stack" data-space="md">
<p class="wl-text-small">{{ "Local demo: add images, PDF or TXT files up to 1 MiB. Advance progress, show an error and retry. Files are not sent to a server." }}</p>
<WlFileUpload
v-model="files"
accept="image/*,.pdf,.txt"
:max-files="3"
:max-size="1048576"
preview
:file-state="fileState"
>
<template #row="{ file, size, previewUrl, state, remove }">
<img
v-if="previewUrl"
class="wl-upload__preview"
:src="previewUrl"
alt=""
/>
<span class="wl-upload__name">{{ file.name }}</span>
<span class="wl-upload__size">{{ size }}</span>
<progress
class="wl-upload__progress"
:value="state?.progress ?? 0"
max="100"
:aria-label="'File progress:' + ' ' + file.name"
></progress>
<span v-if="state?.message" class="wl-upload__message">{{ state.message }}</span>
<WlButton
v-if="state?.status === 'error'"
size="sm"
variant="ghost"
@click="retry(file)"
>{{ "Retry" }}</WlButton>
<WlButton
size="sm"
variant="ghost"
:aria-label="'Remove' + ' ' + file.name"
@click="remove"
>{{ "Delete" }}</WlButton>
</template>
</WlFileUpload>
<div class="wl-inline" data-space="sm">
<WlButton size="sm" :disabled="!files.length" @click="advance">{{ "Advance demo progress" }}</WlButton>
<WlButton
size="sm"
:disabled="!files.length"
variant="ghost"
@click="fail"
>{{ "Show error" }}</WlButton>
<WlButton size="sm" variant="ghost" @click="clear">{{ "Clear lists and errors" }}</WlButton>
</div>
<p class="wl-text-small" role="status">{{ "Files selected:" }} {{ files.length }}</p>
</div>
</template>Limits and local list
File type/size/count limits, replacement and removal, local image previews, controlled per-file progress and a row slot with error/retry.
Documents: type, size and count
PDF or TXT, up to two files, each no larger than 1 MiB. New files extend the list; the button next to a file removes it.
One file replaces the previous file
An image up to 512 KiB. With multiple=false, the next valid selection replaces the current one.
Disabled dropzone and clearing
Enter/Space on the dropzone opens the file picker. Cancelling preserves the list. The component accepts File[] locally; the application uploads files to the server.
Documents: 0. Images: 0.
Full example
<script setup lang="ts">
import { WlButton, type WlFileReject, WlFileUpload } from "legato-ui";
import { ref } from "vue";
const documents = ref<File[]>([]);
const image = ref<File[]>([]);
const revision = ref(0);
const lastRejection = ref("");
interface FileState { progress: number; status: "pending" | "uploading" | "success" | "error"; message?: string }
const states = ref(new Map<File, FileState>());
function fileState(file: File): FileState {
return states.value.get(file) ?? { progress: 0, status: "pending" };
}
function advance(): void {
for (const file of image.value) {
const previous = fileState(file);
if (previous.status === "error") continue;
const progress = Math.min(100, previous.progress + 25);
states.value.set(file, { progress, status: progress === 100 ? "success" : "uploading" });
}
}
function fail(): void {
const file = image.value[0];
if (file) states.value.set(file, { ...fileState(file), status: "error", message: "Local example error. Retry to start again." });
}
function retry(file: File): void {
states.value.set(file, { progress: 0, status: "pending" });
}
const reasons: Record<WlFileReject["reason"], string> = { type: "unsupported type", size: "size limit exceeded", count: "file count exceeded" };
function reject(payload: WlFileReject) {
lastRejection.value = `${payload.file.name}: ${reasons[payload.reason]}.`;
}
function clear() {
documents.value = [];
image.value = [];
states.value.clear();
lastRejection.value = "";
revision.value++;
}
</script>
<template>
<div class="wl-stack" data-space="xl" data-input-example="WlFileUpload">
<section class="wl-stack" data-space="md" aria-labelledby="docs-upload-documents">
<h3 id="docs-upload-documents" class="wl-text-subheading">{{ "Documents: type, size and count" }}</h3>
<p class="wl-text-small">{{ "PDF or TXT, up to two files, each no larger than 1 MiB. New files extend the list; the button next to a file removes it." }}</p>
<WlFileUpload
:key="`documents-${revision}`"
v-model="documents"
accept=".pdf,.txt"
:max-files="2"
:max-size="1048576"
@reject="reject"
/>
<p v-if="lastRejection" class="wl-text-small docs-upload-message">{{ "Last reject event:" }} {{ lastRejection }}</p>
</section>
<section class="wl-stack" data-space="md" aria-labelledby="docs-upload-image">
<h3 id="docs-upload-image" class="wl-text-subheading">{{ "One file replaces the previous file" }}</h3>
<p class="wl-text-small">{{ "An image up to 512 KiB. With multiple=false, the next valid selection replaces the current one." }}</p>
<WlFileUpload
:key="`image-${revision}`"
v-model="image"
accept="image/*"
:multiple="false"
:max-size="524288"
preview
:file-state="fileState"
@reject="reject"
>
<template #row="{ file, size, previewUrl, state, remove }">
<img
v-if="previewUrl"
class="wl-upload__preview"
:src="previewUrl"
alt=""
/>
<span class="wl-upload__name">{{ file.name }}</span>
<span class="wl-upload__size">{{ size }}</span>
<progress
class="wl-upload__progress"
:value="state?.progress ?? 0"
max="100"
:aria-label="'File progress:' + ' ' + file.name"
></progress>
<span v-if="state?.message" class="wl-upload__message">{{ state.message }}</span>
<WlButton
v-if="state?.status === 'error'"
size="sm"
variant="ghost"
@click="retry(file)"
>{{ "Retry" }}</WlButton>
<WlButton
size="sm"
variant="ghost"
:aria-label="'Remove' + ' ' + file.name"
@click="remove"
>{{ "Delete" }}</WlButton>
</template>
</WlFileUpload>
<div class="wl-inline" data-space="sm">
<WlButton size="sm" :disabled="!image.length" @click="advance">{{ "Advance demo progress" }}</WlButton>
<WlButton
size="sm"
:disabled="!image.length"
variant="ghost"
@click="fail"
>{{ "Show error" }}</WlButton>
</div>
</section>
<section class="wl-stack" data-space="md">
<h3 class="wl-text-subheading">{{ "Disabled dropzone and clearing" }}</h3>
<WlFileUpload :model-value="[]" disabled />
<WlButton size="sm" @click="clear">{{ "Clear lists and errors" }}</WlButton>
<p class="wl-text-small wl-text-muted">{{ "Enter/Space on the dropzone opens the file picker. Cancelling preserves the list. The component accepts File[] locally; the application uploads files to the server." }}</p>
<p class="wl-text-small" role="status">{{ "Documents:" }} {{
documents.length
}}{{ ". Images:" }} {{ image.length }}.</p>
</section>
</div>
</template>
<style scoped>
.docs-upload-message { overflow-wrap: anywhere; }
</style>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
v-model: File[]Selected file list (default []).
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
accept | string | Not set | Type filter (comma-separated extensions/MIME types). |
multiple | boolean | true | Multiple files (otherwise a new file replaces the current one). |
maxFiles | number | Not set | File count limit. |
maxSize | number | Not set | Maximum file size in bytes. |
disabled | boolean | false | Disables file selection and drag-and-drop. |
preview | boolean | Not set | Create local image previews while files remain selected. |
fileState | (file: File) => { progress?: number; status?: "pending" | | Not set | Consumer-provided upload status, progress and message for each file. |
pt | WlPt< | Not set | Attributes and callbacks for the component's documented pass-through sections. |
Events
| Event | Payload | When emitted |
|---|---|---|
reject | [payload: WlFileReject] | File rejected: { file, reason: "type" | "size" | "count" }. |
update:modelValue | File[] | Emitted when the component requests a model change; the payload is the next value. |
Slots
| Slot | Type / values | Content |
|---|---|---|
row | row?(props: { file: File; index: number; remove: () => void; size: string; previewUrl: string | | Custom selected-file row with removal, preview and status information. |
Pass-through: pt
Sections WlFileUpload are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | div.wl-upload | Main element of the component. |
drop | div.wl-upload__drop | Keyboard-operable file picker and drop target. |
input | input.wl-upload__input | Native input that receives focus and control attributes. |
errors | ul.wl-upload__errors | List of rejected files and reasons. |
list | ul.wl-upload__list | List of available items. |
row | li.wl-upload__row | One repeated calendar or file-list row. |
preview | img.wl-upload__preview | Local image preview; the component owns its object URL. |
progress | progress.wl-upload__progress | Native per-file progress indicator. |
removeButton | button.wl-upload__remove | Button that removes the associated value or file. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- The drop zone has role=button: Tab focuses it and Enter/Space opens selection. A visible section heading explains accepted files and limits.
- Selected names appear in text; each file has a labelled remove button. disabled prevents selection and removal.
- The component validates accept, maxSize in bytes and maxFiles; reject returns a type/size/count reason and displays error text.
- The model is a local File[]. multiple=false replaces the file with the next valid selection; cancellation preserves the list. The application performs network uploads.
Keyboard and application responsibilities
| Key | Action |
|---|---|
| Tab / Shift+Tab | Move between enabled links, actions and form controls. |
| Enter / Space | Activate native actions; links follow with Enter. |
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesChanges are emitted through v-model. After selection, cancellation and reset, labels and states must remain clear.
In your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.