File Upload
<wa-file-upload>
Drop or select a single file with Yoummday's legacy preview-oriented upload UI.
or click to browse
Examples
Basic usage
Use the default slot to explain what the user can upload.
Drag a file here or click to choose one.
Restrict accepted file types
The accept attribute supports file extensions and MIME types.
PNG, JPG, and WebP are supported.
Hide the preview row
Use no-preview when the surrounding UI already shows the selected file.
Choose a new image to continue.
Notes
wa-file-uploadsubmits a single file with nativeFormData.- The component emits native
inputandchangeevents from the host element. - This component is Yoummday-owned and is separate from Web Awesome Pro's
wa-file-input.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://cdn.yoummday.com/packages/@yoummday/webawesome/0.5.1/dist/components/file-upload/file-upload.js';
After installing Web Awesome via npm, import this component:
import '@yoummday/webawesome/dist/components/file-upload/file-upload.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/file-upload/file-upload.js';
To import this component for React 18 or below, use the following code:
import WaFileUpload from '@yoummday/webawesome/dist/react/file-upload/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | Supportive content rendered inside the drop zone. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
acceptaccept |
Comma-separated list of file extensions or MIME types that are allowed.
Type
string
Default
'.jpg,.jpeg,.png'
|
|
disableddisabled |
Disables the form control.
Type
boolean
Default
false
|
|
form |
By default, form controls are associated with the nearest containing
<form> element. This attribute allows you
to place the form control outside of a form and associate it with the form that has this id. The form must be in
the same document or shadow root for this to work.
Type
HTMLFormElement | null
|
|
iconicon |
The icon to display in the drop zone. Set an empty string to hide it.
Type
string
Default
'mdi:cloud-arrow-up'
|
|
namename |
The name of the input, submitted as a name/value pair with form data.
Type
string | null
Default
null
|
|
noPreviewno-preview |
Disables the filename preview row below the drop zone.
Type
boolean
Default
false
|
|
requiredrequired |
Makes the file upload a required field.
Type
boolean
Default
false
|
|
validationTarget |
Override this to change where constraint validation popups are anchored.
Type
undefined | HTMLElement
|
|
validators |
Validators are static because they have
observedAttributes, essentially attributes to "watch"
for changes. Whenever these attributes change, we want to be notified and update the validator.
Type
Validator[]
Default
[]
|
Methods
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
formStateRestoreCallback() |
Called when the browser is trying to restore element’s state to state in which case reason is "restore", or when the browser is trying to fulfill autofill on behalf of user in which case reason is "autocomplete". In the case of "restore", state is a string, File, or FormData object previously set as the second argument to setFormValue. |
state: string | File | FormData | null,
reason: 'autocomplete' | 'restore'
|
resetValidity() |
Reset validity is a way of removing manual custom errors and native validation. | |
setCustomValidity() |
Do not use this when creating a "Validator". This is intended for end users of components. We track manually defined custom errors so we don't clear them on accident in our validators. |
message: string
|
Events
Learn more about events.
| Name | Description |
|---|---|
change |
Emitted when the selected file is committed. |
input |
Emitted when the selected file changes. |
wa-invalid |
Emitted when the form control has been checked for validity and its constraints aren't satisfied. |
CSS Custom Properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--wa-file-upload-border-color |
Border color of the drop zone.
|
--wa-file-upload-border-style |
Border style of the drop zone.
|
--wa-file-upload-border-width |
Border width of the drop zone.
|
--wa-file-upload-min-height |
Minimum height of the drop zone.
|
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
clear-button |
The button that clears the selected file. |
::part(clear-button)
|
dropzone |
The clickable and droppable surface. |
::part(dropzone)
|
file-upload |
The component's outer wrapper. |
::part(file-upload)
|
icon |
The upload icon. |
::part(icon)
|
input |
The internal native file input. |
::part(input)
|
preview |
The preview row shown after a file is selected. |
::part(preview)
|
preview-name |
The selected file name. |
::part(preview-name)
|
slot-container |
The container for the slotted element. |
::part(slot-container)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.