Create

Form

File Upload

New
Copy page View as Markdown Open in ChatGPT Open in Claude

A drop zone and a list of files for choosing files to upload.

Usage#

app.component.ts
import { WdsFileUploadComponent } from '@wds/angular/file-upload';

The element collects files; it does not send them. Read files (or the form data) and upload them yourself, showing the progress with setFileStatus(). Name the field with a wds-field-label in a wds-field (or label).

Examples#

Default#

Click the drop zone (or press Enter or Space) to open the file picker, or drag a file onto it. Without multiple a new file replaces the previous one. The hint comes from accept and max-size (in bytes); images get a preview.

Cover image

Multiple files#

multiple keeps adding files to the list, up to max-files. The same file added twice is listed once.

Attachments Invoices or photos of receipts.

Upload progress and rejected files#

wds-change gives the files; setFileStatus(file, { progress }) shows a progress bar under a file, { error } an error, and null clears it. Files that do not pass accept, max-size or max-files are not added and fire wds-reject with the reason.

Photos

Custom drop zone#

Content in the default slot replaces the icon, the text and the hint; --wds-file-upload-min-height: 0 makes the zone as low as its content. Use text and icons only: the drop zone is a button.

Resume Attach a file PDF or DOCX

Disabled#

disabled blocks the picker and dropping, and excludes the files from the form.

Documents Uploads are paused during maintenance.

Forms#

Integration with Angular forms. Pick the API your app uses.

Signal forms#

WdsFileUploadField connects the field to [formField]; the model is File[]. In signal forms required() does not treat an empty array as empty, so check the number of files with validate() (here with requiredError); required() still marks the field as required.

ReceiptsSubmit claim

Submitted: —

Template-driven#

WdsFileUploadValueAccessor makes ngModel work on wds-file-upload. Inside a <form> the field needs a name.

ReceiptsSubmit claim

Submitted: —

Reactive forms#

The same WdsFileUploadValueAccessor works with formControl and formControlName; an empty list fails Validators.required.

ReceiptsSubmit claim

Submitted: —

API References#

wds-file-upload#

A field for files: a drop zone that opens the file picker on click (or Enter and Space) and takes files dragged onto it, and a list of the chosen files with a preview, the size and a remove button. accept, max-size and max-files filter the files as they are added; the rejected ones fire wds-reject. The element does not upload anything: read files (or the form data) and send them yourself. During an upload setFileStatus() shows a progress bar or an error under a file. In a <form> the files are submitted under name, and required validates as in a native file field.

Attributes

AttributeTypeDefaultDescription
acceptstring''Accepted types, as in <input type="file">: extensions and MIME types, e.g. image/*,.pdf.
multiplebooleanfalseAllows more than one file. Without it a new file replaces the previous one.
max-files.maxFilesnumber | undefinedLargest number of files (with multiple).
max-size.maxSizenumber | undefinedLargest size of one file, in bytes (e.g. 5242880 for 5 MB).
namestring''Field name in the form; each file is submitted under it.
disabledbooleanfalseDisables the field and excludes it from form submission.
requiredbooleanfalseAt least one file is required for the form to be valid.
invalidbooleanfalseError state: red border of the drop zone and aria-invalid.
hide-list.hideListbooleanfalseHides the built-in list (e.g. to show the files your own way).
labelstring''Accessible name of the drop zone when the field is not in a wds-field with a label.

Properties

PropertyDescription
filesFile[]The chosen files. Setting it replaces the list (e.g. [] to clear it).

Events

EventDescription
wds-rejectCustomEvent<WdsFileUploadRejectDetail>Some of the added files did not pass accept, max-size or max-files.
wds-changeCustomEvent<WdsFileUploadChangeDetail>Files were added or removed.
wds-removeCustomEvent<WdsFileUploadRemoveDetail>The user removed a file from the list.

Methods

MethodDescription
browse()Opens the file picker.
addFiles(files: Iterable<File>)Adds files as if they were dropped (they pass the same checks).
removeFile(file: File)Removes a file from the list.
clear()Removes all files.
setFileStatus(file: File, status: WdsFileUploadStatus | null)Shows the upload progress (0–100) or an error under a file; null removes the status.
formResetCallback()
formDisabledCallback(disabled: boolean)
checkValidity()Returns true when the value is valid; otherwise fires invalid on the element.
reportValidity()Like checkValidity(), and shows the browser validation bubble when the value is invalid.
setCustomValidity(message: string)Sets a custom validation error (an empty string clears it), like input.setCustomValidity().

Slots

SlotDescription
(default)Content of the drop zone instead of the default icon, text and hint (text and icons only: the drop zone is a button).

CSS parts (::part)

PartDescription
dropzoneThe drop zone (a <button>).
hintThe hint under the text of the drop zone.
listThe list of files.
fileA row of the list.
removeThe remove button of a row.

CSS custom properties

PropertyDescription
--wds-file-upload-min-heightMinimum height of the drop zone (default 9rem).

Accessibility#

Screen reader#

The drop zone is a native button named by the wds-field-label (or label), with the hint (types, size, number of files) as its description. Dragging and dropping is optional: every file can be added with the keyboard.

Added, removed and rejected files are announced in a status region, e.g. "photo.jpg added." or "2 files not added." Show the reasons for rejected files on the page as well (see the example).

The files are a list; each remove button is named "Remove" with the file name. After a removal focus moves to the next remove button, or back to the drop zone.

An upload progress bar is a progressbar named "Uploading" with the file name. invalid and required set aria-invalid and the validation state, as in a native file field.

Keyboard support#

KeyFunction
EnterSpaceOn the drop zone: opens the file picker.
TabMoves from the drop zone to the remove buttons of the files.
EnterSpaceOn a remove button: removes the file.
Footer