File Upload
<afp-file-upload>
A file upload component that allows users to select files.
Examples #
File Size Limit #
Use the maxSize attribute to set a maximum file size in bytes (5MB = 5242880 bytes).
Multiple Files #
Use the multiple attribute to allow selecting multiple files.
File Type Restriction #
Use the accept attribute to restrict file types.
Retry Upload #
Use the showRetry (showretry) attribute to enable the retry upload button. This button is displayed only when the state is error.
File State #
Use the state attribute to indicate the current status of the uploaded file(s). Any value from the AfpVariant enum can be used,
Disabled #
Use the disabled attribute to disable the file upload.
Custom Title and Hint #
Use the title and hint slots to customize the upload area text.
Custom Icon #
Use the icon slot to customize the upload area icon.
Custom Retry Upload Icon #
Use the retry-icon slot to customize the retry upload button icon.
Properties
Learn more about properties.
| Name | Description | Reflects | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
accept
|
Accepted file types (e.g., 'image/*', '.pdf,.doc').
Type
string
Default
'' |
|||||||||||||||||
multiple
|
Allow multiple file selection.
Type
boolean
Default
false |
|||||||||||||||||
maxSize
maxsize
|
Maximum file size in bytes.
Type
number
Default
0 |
|||||||||||||||||
disabled
|
Disable the file upload.
Type
boolean
Default
false |
|
||||||||||||||||
state
|
State of the uploaded file(s).
Type
AfpVariant
|
|||||||||||||||||
showRetry
showretry
|
State of the uploaded file(s).
Type
boolean
Default
false |
|
Events
Learn more about events.
| Name | Return | Description |
|---|---|---|
afp-file-change
|
File[]
|
Emitted when files are selected or removed.
|
Slots
Learn more about slots.
| Name | Description |
|---|---|
icon
|
The upload area icon. Defaults to cloud-upload icon.
|
title
|
The upload area title text.
|
hint
|
The upload area hint text.
|
file-icon
|
The icon for each file item. Defaults to file-earmark icon.
|
remove-icon
|
The icon for the remove file button. Defaults to x icon.
|
retry-icon
|
The icon for the retry upload file button. Defaults to arrow-counterclockwise icon.
|
Internationalization
Learn more about internationalization.
| Key | Description |
|---|---|
file-upload.remove-file.aria-label
|
The default `aria-label` text for the remove file button.
|
file-upload.retry-upload-file.aria-label
|
The default `aria-label` text for the retry upload file button.
|
CSS Parts
Learn more about CSS Parts.
| Name | Description | Selector |
|---|---|---|
base
|
The component's base wrapper.
|
::part(base)
|
hidden-file-input
|
The hidden file input element.
|
::part(hidden-file-input)
|
upload-area
|
The file upload area.
|
::part(upload-area)
|
content
|
The content wrapper inside the upload area.
|
::part(content)
|
content-icon
|
The icon inside the upload area.
|
::part(content-icon)
|
content-text-wrapper
|
The text wrapper inside the upload area.
|
::part(content-text-wrapper)
|
content-title
|
The title text inside the upload area.
|
::part(content-title)
|
content-hint
|
The hint text inside the upload area.
|
::part(content-hint)
|
item-list
|
The list wrapper for selected files.
|
::part(item-list)
|
item-item
|
The individual file item wrapper.
|
::part(item-item)
|
item-icon
|
The icon for each file item.
|
::part(item-icon)
|
item-info
|
The info wrapper for each file item.
|
::part(item-info)
|
item-info-name
|
The file name text for each file item.
|
::part(item-info-name)
|
item-info-size
|
The file size text for each file item.
|
::part(item-info-size)
|
item-actions
|
The actions for each file item.
|
::part(item-actions)
|
item-actions-remove-button
|
The remove file button for each file item.
|
::part(item-actions-remove-button)
|
item-actions-retry-button
|
The retry upload file button for each file item.
|
::part(item-actions-retry-button)
|
file-actions-retry-icon
|
The icon for retry upload file button.
|
::part(file-actions-retry-icon)
|
CSS Custom Properties
| Name | Description | Default |
|---|---|---|
--afp-file-upload-disabled-opacity
|
The opacity of the file-upload when disabled.
|
0.5
|
--afp-file-upload-size
|
The size of the file-upload component.
|
8rem
|
Dependencies
The component automatically brings in the listed items, including any nested dependencies that may exist.
Importing
Using the bundle is the recommended method to include components. If you’d rather handle imports manually, you can use the code examples below.
import '@afp-design-system/core/dist/components/file-upload/file-upload.js';