File input component is a web component that allows users to select a file from their device. It is used to upload files in a user-friendly way.
Design system docsExamplesSizes
<dap-ds-stack><dap-ds-file-inputsize="xs"description="Upload your resume"accept=".jpg,.docx,.png,.heic"label="Auto upload resume"uploadUrl="https://9daf1d71-c24f-4a02-8861-701f8ff4a9c8.mock.pstmn.io/upload/success"tooltip="File tooltip text"></dap-ds-file-input><dap-ds-file-inputdescription="Upload your resume"accept=".jpg,.docx,.png,.heic"label="Auto upload resume"uploadUrl="https://9daf1d71-c24f-4a02-8861-701f8ff4a9c8.mock.pstmn.io/upload/success"tooltip="File tooltip text"></dap-ds-file-input><dap-ds-file-inputsize="lg"description="Upload your resume"accept=".jpg,.docx,.png,.heic"label="Auto upload resume"uploadUrl="https://9daf1d71-c24f-4a02-8861-701f8ff4a9c8.mock.pstmn.io/upload/success"tooltip="File tooltip text"></dap-ds-file-input></dap-ds-stack>
Auto upload files
File input component can be set to automatically upload files. When the user selects a file, it is automatically uploaded to the server. The autoupload attribute should be set to true, and the uploadUrl attribute should be set to the server URL.
<dap-ds-file-inputdescription="Upload your resume"accept=".jpg,.docx,.png,.heic"label="Auto upload resume"autouploaduploadUrl="https://9daf1d71-c24f-4a02-8861-701f8ff4a9c8.mock.pstmn.io/upload/success"tooltip="File tooltip text"></dap-ds-file-input>
File list
With the <dap-ds-file-input-list> component, you can display a list of uploaded files. The for attribute should be set to the ID of the file input component.
<><dap-ds-file-inputsize="xs"id="fileInput"description="Upload your resume"accept=".jpg,.docx,.png,.heic"label="Auto upload resume"autouploaduploadUrl="https://9daf1d71-c24f-4a02-8861-701f8ff4a9c8.mock.pstmn.io/upload/success"tooltip="File tooltip text"></dap-ds-file-input><dap-ds-file-input-listfor="fileInput"></dap-ds-file-input-list></>
Show drop zone
The showDropZone attribute can be set to true to show a drop zone for the file input component.
<><dap-ds-file-inputsize="xs"id="fileInput"description="Upload your resume"accept=".jpg,.docx,.png,.heic"label="Dropzone"showDropZoneuploadUrl="https://9daf1d71-c24f-4a02-8861-701f8ff4a9c8.mock.pstmn.io/upload/success"tooltip="File tooltip text"></dap-ds-file-input><dap-ds-file-input-listfor="fileInput"></dap-ds-file-input-list></>
File events, handling file upload statuses
Please check the console for the file upload status events. You can find the available events in the Events section below.
The first upload will be always successful, the second will always fail. A confirmation modal will be shown when the user tries to remove a file.
Example
HTML
<dap-ds-file-inputref={succcessRef}id="fileInput1"description="Always success upload"accept=".jpg,.docx,.png,.heic"label="Upload your recipes"autouploaduploadUrl="https://9daf1d71-c24f-4a02-8861-701f8ff4a9c8.mock.pstmn.io/upload/success"tooltip="File tooltip text"></dap-ds-file-input><dap-ds-file-input-listfor="fileInput1"></dap-ds-file-input-list><dap-ds-modalid="confirmModal"header="Are you sure?"description="Confirm your choice!"okButtonDangerokButtonLabel="Delete"></dap-ds-modal>
In the dds-file-change event, you can prevent the files from being added by calling event.preventDefault(),this will reject all files, or adding the files to the canceledFiles set on the event detail object. This will reject only the files in the canceledFiles set.
Fired when a file deletion from server encounters an error.
{file: FileListElement, error: Error }
dds-file-change
Fired when the file input value changes. This event is cancelable. Event detail contains: `newFiles` (just the files being added in this operation), `currentFiles` (all files that were already selected before this operation), `files` (all files after merge with existing when keepValue=true), and `canceledFiles` (Set to add files you want to reject). You can either: (1) Call `event.preventDefault()` to reject all files, or (2) Add specific files to `canceledFiles` to reject only those files.
Fired when the file input value changes. This event is cancelable. Event detail contains: `files` (all files after merge with existing when keepValue=true).
{files: File[] }
CSS Parts
Part Name
Description
base
The main file input container.
input
The file input control.
label
The file input label.
description
The file input description.
feedback
The file input feedback.
tooltip
The file input tooltip.
upload-progress
The upload progress container.
browse-button
The browse button.
upload-button
The upload button.
dropzone
The dropzone area.
file-list
The file list container.
file-list-item
Individual file list items.
How to Use CSS Parts
You can style CSS parts using the ::part() pseudo-element selector:
/* Target a specific part */.my-custom-dap-ds-file-input::part(base){/* Your custom styles */}/* Target multiple parts */.my-custom-dap-ds-file-input::part(base),.my-custom-dap-ds-file-input::part(input){/* Shared styles */}