File input

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 docs

Examples Auto upload files

File input component can be set to auto 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-input
    description="Upload your resume"
    accept=".jpg,.docx,.png,.heic"
    label="Auto upload resume"
    autoupload
    uploadUrl="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-input
    id="fileInput"
    description="Upload your resume"
    accept=".jpg,.docx,.png,.heic"
    label="Auto upload resume"
    autoupload
    uploadUrl="https://9daf1d71-c24f-4a02-8861-701f8ff4a9c8.mock.pstmn.io/upload/success"
    tooltip="File tooltip text">
  </dap-ds-file-input>

  <dap-ds-file-input-list for="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. 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-input
  ref={succcessRef}
  id="fileInput1"
  description="Always success upload"
  accept=".jpg,.docx,.png,.heic"
  label="Upload your recepies"
  autoupload
  uploadUrl="https://9daf1d71-c24f-4a02-8861-701f8ff4a9c8.mock.pstmn.io/upload/success"
  tooltip="File tooltip text">
</dap-ds-file-input>

<dap-ds-file-input-list for="fileInput1">
</dap-ds-file-input-list>

<dap-ds-modal
  id="confirmModal"
  header="Are you sure?"
  description="Confirm your choice!"
  okButtonDanger
  okButtonLabel="Delete">
</dap-ds-modal>
Js
fileInput.addEventListener('dds-file-change', event => {
  const files = event.detail.files

  console.log('dds-file-change', files)
})

fileInput.addEventListener('dds-upload-complete', e => {
  console.log('dds-upload-complete', e)
  e.detail.item.feedbackType = 'positive'
  e.detail.item.feedback = 'success'
})

fileInput.current?.addEventListener('dds-upload-error', e => {
  console.log('dds-upload-error', e)
  e.detail.item.feedbackType = 'negative'
  e.detail.item.feedback = 'error'
})

fileInput.addEventListener('dds-upload-error', () => {
  console.log('dds-upload-error', 'all upload completed successfully')
})

fileInput.addEventListener('dds-upload-progress', event => {
  console.log('uploading:', event.detail.progress)
})

fileInput.addEventListener('dds-file-removed', event => {
  const confirmModal = document.getElementById('confirmModal')
  confirmModal.addEventListener('dds-ok', () => {
    event.detail.cancel.allow(true)
  })

  confirmModal.addEventListener('dds-cancel', () => {
    event.detail.cancel.reject()
  })

  confirmModal.show()
})
Importing
import { DapDSFileInput } from 'dap-design-system/dist/dds'
Importing React
import { DapDSFileInputReact } from 'dap-design-system/dist/react'
Slots

No slots available.

Attributes
PropertyTypeDefaultDescription
subtlebooleanFont weight of the feedback label. Default is false which is bold.
namestringThe name of the file input.
valuestringThe value of the file input.
statusstringThe status of the file input. Can be 'success' or 'error'.
pathstringThe server path for file uploads.
autouploadbooleanWhether to upload files immediately upon selection.
uploadPropertystring'file'The name of the property to use when uploading files.
uploadMethodstring'POST'The HTTP method to use when uploading files.
withCredentialsbooleanfalseWhether to send credentials with the file upload request.
maxFilesstringThe maximum number of files that can be uploaded.
maxFileSizestringThe maximum size of files that can be uploaded.
sizestringThe size of the file input. Can be 'small', 'medium', or 'large'.
labelstringThe label for the file input.
descriptionstringThe description for the file input.
feedbackstringThe feedback for the file input.
feedbacktypestringThe type of feedback for the file input. Can be 'error' or 'warning'.
tooltipstringThe tooltip for the file input.
requiredbooleanWhether the file input is required.
optionalbooleanWhether the file input is optional.
disabledbooleanWhether the file input is disabled.
multiplebooleanfalseWhether the file input accepts multiple files.
acceptstringThe file types that the file input accepts.
uploadUrlstringThe URL to upload files to.
keepValuebooleanfalseWhether to keep the value of the file input when new files are selected.
uploadButtonLabelstringThe label for the upload button.
Events
Event NameDescription
dds-upload-startFired when a file upload starts.
dds-upload-progressFired during file upload progress.
dds-upload-completeFired when a file upload completes successfully.
dds-upload-errorFired when a file upload encounters an error.
dds-all-uploads-completeFired when all file uploads are complete.
dds-file-removedFired when a file is removed from the file input.
CSS Parts
Part NameDescription
baseThe main file input container.
inputThe file input control.
labelThe file input label.
descriptionThe file input description.
feedbackThe file input feedback.
tooltipThe file input tooltip.