Reference

FileUpload

File input; bind: holds what was chosen, and on change hears it.

FileUpload(accept: String, label: String, multiple: Bool, …) { … }

Before 5.0

accept

label

multiple

disabled

dropzone

No picture chosen

Example

wf

state photo: File? = null FileUpload(bind: photo, accept: "image/*", label: "Profile picture") if let p = photo { Text("Chosen: {p.name}").muted } else { Text("No picture chosen").muted }

A drop zone for several files

wf

state files: [File] = [] FileUpload(bind: files, accept: ".pdf,.png,.jpg", label: "Attachments").dropzone.multiple Text("{files.length} file(s) attached")

Disabled

wf

state contract: File? = null FileUpload(bind: contract, accept: ".pdf", label: "Signed contract").disabled

Props

Props of FileUpload
PropTypeUnsetMeaning

accept:

String

any file

The kinds of file it offers: MIME types or extensions, comma-separated (image/*, .pdf,.doc)

label:

String

none (Choose files with .dropzone)

The label drawn above the file input and its accessible name; with .dropzone, the words of its Choose button

multiple:

Bool

false

Several files at once: bind: holds a [File], and with .dropzone each choice adds to the list. Written as a flag, .multiple, or multiple: true.

disabled:

Bool

false

Whether the control is inert: it cannot be focused or changed, and a form does not send it. Written as a flag, .disabled, or disabled: true.

bind:

State

The state the choice is written to: a File? (null when none), or a [File] with .multiple

dropzone:

Bool

false

An area files are dropped on or chosen into, each listed with its name, a preview if it is an image, and a button to take it out. Written as a flag, .dropzone, or dropzone: true.

Attribute families: global, aria, data, input. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.

Flags and cases

A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.

.multiple

.disabled

.dropzone

Events

The DOM events it is drawn to answer. Any other DOM event works too, in an on … { } handler.

DOM events FileUpload answers
EventSendsMeaning
on changeDOMThe value was committed

Every element also takes the props, the events and the attribute families listed on every element.

Slots

children

Renders with the class wf-file-upload, stable across releases, so a stylesheet may target it.