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
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
state files: [File] = []
FileUpload(bind: files, accept: ".pdf,.png,.jpg", label: "Attachments").dropzone.multiple
Text("{files.length} file(s) attached")
Disabled
state contract: File? = null
FileUpload(bind: contract, accept: ".pdf", label: "Signed contract").disabled
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
accept: | String | any file | The kinds of file it offers: MIME types or extensions, comma-separated ( |
label: | String | none ( | The label drawn above the file input and its accessible name; with |
multiple: | Bool | false | Several files at once: |
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, |
bind: | State | The state the choice is written to: a | |
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, |
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.
| Event | Sends | Meaning |
|---|---|---|
on change | DOM | The 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.