Skip to content
Focsd homeFocsd homeFocsd
Forms

File upload

A drop zone and file chooser, with type and size checks.

  • Tag: focsd-file-upload
  • Pattern: Button + drop zone + list
  • Category: Forms

Example

HTML
<div class="stack">
<focsd-file-upload
label="Attachments"
accept=".pdf,image/png"
multiple
max-size="1000000"
hint="PDF or PNG, up to 1 MB"></focsd-file-upload>
</div>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-file-upload.js';
</script>
<focsd-file-upload label="Attachments" accept=".pdf,image/png" multiple max-size="1000000" hint="PDF or PNG, up to 1 MB"></focsd-file-upload>

API

Attributes

AttributePropertyTypeDefault
namenamestring—
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadOnlybooleanfalse
aria-labelhostAriaLabelstring | nullnull
aria-descriptionhostAriaDescriptionstring | nullnull
aria-labelledbyhostAriaLabelledBystring | nullnull
aria-describedbyhostAriaDescribedBystring | nullnull
label-positionlabelPosition'top' | 'start' | 'end' | undefined—
hinthintstring—
errorerror——
warningwarningstring | undefined—
successsuccessstring | undefined—
error-messageerrorMessagestring | undefined—
warning-messagewarningMessagestring | undefined—
warning-patternwarningPatternstring | undefined—
labellabelstring—
acceptacceptstring—
multiplemultiplebooleanfalse
max-sizemaxSizenumber0
capturecapturestring—
webkitdirectorywebkitdirectorybooleanfalse

Methods

MethodDescription
describedByIds()IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()Show (or clear) the error from the control's own checks: required, type, pattern, min, max and the like. Uses error-message, else the browser's localized message. An error the author set (a server error, say) is left as it is.
clearValidation()Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)For subclasses: fire the value events, as a native control does on a user edit: input (bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)For subclasses: the text of the elements an ID reference list names, resolved in the host's tree (ID references cannot cross a shadow root), joined by spaces.
showPicker()Open the native file picker from code, like native showPicker().
addFiles(list)Validate and add files; rejected ones are reported, never added.
removeFile(file)Remove a selected file and return focus to the choose button.

Events

EventDescription
inputFired on every user edit of the value.
changeFired when the user commits a change to the value or state.

CSS parts

Style the inside of the component with ::part(), for example focsd-file-upload::part(dragging).

PartDescription
draggingAdded to the drop zone while files are dragged over it.
drop-textThe "or drop files here" text.
dropzoneThe area that accepts dropped files.
errorOne rejected file and why; also matches the control's `error` message (use `rejection` for the file only).
errorsThe list of rejected files and why.
fileOne selected file.
file-nameA file's name.
file-sizeA file's size.
filesThe list of selected files.
groupThe group element.
labelThe label element.
layoutThe wrapper that places the label beside or above the body.
bodyThe drop zone, file lists, hint and message.
hintThe author's hint.
messageThe shown error, warning or success message (also `error`, `warning` or `success`).
message-iconThe message's icon.
announcerThe visually hidden status region.
rejectionOne rejected file and why (never the control's `error` message).
removeA file's remove button.
statusThe status element.
triggerThe trigger element.

Accessibility

  • capture, webkitdirectory and showPicker() reach the native file picker.
  • A visible "Choose files" button opens the native picker, so dragging is never required (WCAG 2.5.7).
  • Rejected files are reported in a role="alert" region and never added; a polite status reports "2 files selected".
  • Each file has a "Remove report.pdf" button; focus returns to the choose button after removal.
  • Files cannot be restored after back/forward navigation (browsers do not allow it).