Skip to the content
Konstruktor UI

Actions and inputs

File drop

<kui-file-drop> around a native <input type="file">: files can be dropped on the area or chosen with the browser’s dialog, and each chosen file is listed with its size and a remove button. The input keeps the files for the form.

<kui-file-drop> needs kui.js; the markup works without it as described below

Examples

Documents for a claim

accept limits the types; a dropped file of another type is left out. max-size (in bytes) refuses a bigger file and announces data-too-big. Choose two or three files to see the list.

Documents
    HTML
    <div class="kui-field">
      <span class="kui-label" id="file-drop-docs-label">Documents</span>
      <kui-file-drop class="kui-file-drop" max-size="10485760" data-too-big="A file is larger than 10 MB and was not added.">
        <label class="kui-file-drop__zone">
          <svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#upload"></use></svg>
          <span>Drop files here or <strong>choose them</strong></span>
          <span class="kui-hint" id="file-drop-docs-hint">PDF, JPG or PNG, up to 10 MB each</span>
          <input type="file" name="documents" multiple accept=".pdf,.jpg,.jpeg,.png" aria-labelledby="file-drop-docs-label" aria-describedby="file-drop-docs-hint">
        </label>
        <ul class="kui-file-list" aria-live="polite"></ul>
      </kui-file-drop>
    </div>

    One file only

    Without multiple a new file replaces the one before.

    HTML
    <kui-file-drop class="kui-file-drop">
      <label class="kui-file-drop__zone">
        <svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#image"></use></svg>
        <span>Drop your photo here or <strong>choose one</strong></span>
        <span class="kui-hint">Square, at least 400 by 400 pixels</span>
        <input type="file" name="photo" accept="image/*">
      </label>
    </kui-file-drop>

    States

    Every state

    Hover darkens the dashed line. While files are dragged over it the line turns solid and the area takes the accent surface (data-dragging). Keyboard focus on the hidden input rings the whole area. Invalid gives the line the danger colour. The list below is the markup the element writes for each chosen file; a long name is cut with an ellipsis and its full text is in the title.

    Add the signed contract as a PDF.

    • Ugovor_o_zakupu_poslovnog_prostora_Čačak_potpisan.pdf1.2 MB
    • Personalausweis_Rückseite.jpg864 kB
    HTML
    <kui-file-drop class="kui-file-drop">
      <label class="kui-file-drop__zone">
        <svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#upload"></use></svg>
        <span>Drop the signed contract here or <strong>choose it</strong></span>
        <input type="file" name="contract" accept=".pdf" required aria-invalid="true" aria-describedby="file-drop-s-e">
      </label>
    </kui-file-drop>
    <p class="kui-error-text" id="file-drop-s-e"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#circle-alert"></use></svg><span>Add the signed contract as a PDF.</span></p>
    <ul class="kui-file-list" aria-label="Chosen files, as the element draws them">
      <li><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#file"></use></svg><span class="kui-file-list__name" title="Ugovor_o_zakupu_poslovnog_prostora_Čačak_potpisan.pdf">Ugovor_o_zakupu_poslovnog_prostora_Čačak_potpisan.pdf</span><span class="kui-file-list__size">1.2 MB</span><button class="kui-button kui-button--ghost kui-button--icon kui-button--sm" type="button" aria-label="Remove Ugovor_o_zakupu_poslovnog_prostora_Čačak_potpisan.pdf"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#close"></use></svg></button></li>
      <li><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#file"></use></svg><span class="kui-file-list__name" title="Personalausweis_Rückseite.jpg">Personalausweis_Rückseite.jpg</span><span class="kui-file-list__size">864 kB</span><button class="kui-button kui-button--ghost kui-button--icon kui-button--sm" type="button" aria-label="Remove Personalausweis_Rückseite.jpg"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#close"></use></svg></button></li>
    </ul>

    Classes and attributes

    kui-file-drop.kui-file-drop
    The element around the drop area and the list.
    label.kui-file-drop__zone
    The area: a label around the input, so a press anywhere opens the dialog.
    input type="file" multiple, accept
    Several files or one; the types allowed.
    max-size, data-too-big
    The largest file in bytes, and the message announced when one is too big.
    .kui-file-list
    The list of chosen files. The element makes one when there is none.
    data-dragging
    Set on the element while files are dragged over the area.

    Keyboard

    Tab
    Moves to the area (the input inside it).
    Enter or Space
    Opens the browser’s dialog to choose files.
    Tab
    Then to each file’s remove button.

    Accessibility

    • The real control is the native file input, so it is announced as a file button with its name and hint.
    • Dropping is never the only way: the same area opens the dialog.
    • The list is a polite live region; the count of chosen files is announced from the kit’s words (“2 files chosen”).
    • Each remove button is named with the file’s name, and focus moves to the next remove button or back to the area after it.

    Do and do not

    Do

    • Say the types and the size limit before the person chooses.
    • Show every chosen file with its size, so a wrong one can be removed.
    • Check the files again on the server.

    Do not

    • Do not make dropping the only way to add a file.
    • Do not upload the moment a file is chosen when the person may still remove it.
    • Do not trust accept alone; it only filters the dialog.