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>