Search docs

File Upload

A control for selecting and dropping files with validation and form support.

File Upload uses native <input type="file">, <label>, and <button type="button"> semantics for accessible file picking, drag-and-drop, and form submission.

Drag and drop a file here, or

import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { FileUpload, type FileUploadFile } from '@leve-ui/file-upload';
import { LuFile, LuTrash2, LuUpload } from '@qwikest/icons/lucide';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);
  const files = useSignal<FileUploadFile[]>([]);

  return (
    <FileUpload.Root bind:files={files} class="file-upload-default">
      <FileUpload.Label class="file-upload-default-label">Attachment</FileUpload.Label>
      <FileUpload.Dropzone class="file-upload-default-dropzone">
        <LuUpload class="file-upload-default-upload-icon" aria-hidden="true" />
        <p class="file-upload-default-text">Drag and drop a file here, or</p>
        <FileUpload.Trigger class="file-upload-default-trigger">Choose file</FileUpload.Trigger>
      </FileUpload.Dropzone>
      <FileUpload.HiddenInput />
      {files.value.length > 0 && (
        <FileUpload.ItemGroup class="file-upload-default-list">
          {files.value.map((file) => (
            <FileUpload.Item key={file.id} file={file} class="file-upload-default-item">
              <LuFile class="file-upload-default-file-icon" aria-hidden="true" />
              <div class="file-upload-default-item-meta">
                <FileUpload.ItemName class="file-upload-default-item-name" />
                <FileUpload.ItemSize class="file-upload-default-item-size" />
              </div>
              <FileUpload.ItemDeleteTrigger class="file-upload-default-delete">
                <LuTrash2 class="file-upload-default-delete-icon" aria-hidden="true" />
              </FileUpload.ItemDeleteTrigger>
            </FileUpload.Item>
          ))}
        </FileUpload.ItemGroup>
      )}
    </FileUpload.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/file-upload

Anatomy#

import { FileUpload } from '@leve-ui/file-upload'; // or '@leve-ui/core'

<FileUpload.Root>
  <FileUpload.Label />
  <FileUpload.Dropzone>
    <FileUpload.Trigger />
  </FileUpload.Dropzone>
  <FileUpload.HiddenInput />
  <FileUpload.ItemGroup>
    <FileUpload.Item file={file}>
      <FileUpload.ItemName />
      <FileUpload.ItemSize />
      <FileUpload.ItemDeleteTrigger />
    </FileUpload.Item>
  </FileUpload.ItemGroup>
</FileUpload.Root>
PartElementDescription
FileUpload.Root<div>Wraps the parts, manages accepted files, and validates selections.
FileUpload.Label<label>Labels the hidden file input via for.
FileUpload.Dropzone<div>Drag-and-drop area that also opens the file picker on click.
FileUpload.Trigger<button>Opens the native file picker when clicked or activated via keyboard.
FileUpload.HiddenInput<input type="file">Visually hidden native file input synchronized with accepted files.
FileUpload.ItemGroup<ul>List container for accepted files.
FileUpload.Item<li>Represents a single accepted file entry.
FileUpload.ItemName<span>Displays the file name (renders {file.name} automatically).
FileUpload.ItemSize<span>Displays the formatted file size using formatFileSize.
FileUpload.ItemDeleteTrigger<button>Removes the enclosing item from the file list.

Examples#

Multiple#

Pass multiple on FileUpload.Root to allow selecting and appending multiple files.

Drag and drop multiple files here

Validation#

Use accept, maxFiles, maxFileSize, and minFileSize to validate files and handle rejected items with onFileReject$.

Drop up to 2 image files (max 1 MB)

Disabled#

disabled on FileUpload.Root disables the dropzone, trigger, hidden input, and delete buttons.

File upload is disabled

With Field#

Inside a Field.Root, use Field.Label and Field.Description. The Field provides the IDs, description, and disabled / required / invalid states.

Drop your PDF resume here

Accepted format: PDF.

With Form#

FileUpload.HiddenInput keeps the native <input type="file">.files synchronized via DataTransfer so new FormData(form) receives accepted files and <button type="reset"> clears them.

Drop files or click to select

API Reference#

Root#

PropDefaultType
ids–{ input?: string; label?: string; dropzone?: string; trigger?: string }

Overrides the element IDs of the parts. Inside a Field, input and label IDs are inherited from the Field.

defaultFiles[]FileUploadFile[]

The initial list of files (uncontrolled).

bind:files–Signal<FileUploadFile[]>

A signal holding the list of accepted files (controlled).

onFilesChange$–QRL<(files: FileUploadFile[]) => void>

Called when the accepted file list changes.

onFileReject$–QRL<(rejections: FileRejection[]) => void>

Called when one or more files fail validation.

accept–string

Comma-separated list of accepted file types (MIME types, wildcards like image/*, or extensions like .png).

multiplefalseboolean

Whether multiple files can be selected at once.

maxFiles–number

Maximum number of accepted files. Defaults to 1 unless multiple is true. Setting maxFiles greater than 1 also enables multiple on the underlying <input>.

maxFileSize–number

Maximum allowed file size in bytes.

minFileSize–number

Minimum allowed file size in bytes.

disabledfalseboolean

Disables the file upload control. Inside a Field or Fieldset, the inherited disabled also applies.

readOnlyfalseboolean

Marks the file upload control as read-only. Inside a Field, the inherited readOnly also applies.

requiredfalseboolean

Marks the file upload control as required. Inside a Field, the Field's required also applies.

invalidfalseboolean

Marks the file upload control as invalid. Inside a Field, the Field's invalid also applies.

Also accepts all <div> attributes.

Data attributeValue
data-leve-file-uploadAlways present
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Label#

No props of its own. Accepts all <label> attributes.

Data attributeValue
data-leve-file-upload-labelAlways present
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Dropzone#

PropDefaultType
disableClickfalseboolean

Prevents clicking the dropzone from opening the file picker.

Also accepts all <div> attributes.

Data attributeValue
data-leve-file-upload-dropzoneAlways present
data-state"idle" | "dragging"
data-draggingPresent while dragging files over the dropzone
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Trigger#

No props of its own. Accepts all <button> attributes.

Data attributeValue
data-leve-file-upload-triggerAlways present
data-disabledPresent when disabled or read-only
data-readonlyPresent when read-only
data-invalidPresent when invalid

HiddenInput#

PropDefaultType
form–string

The id of the form element to associate the input with.

Also accepts all <input> attributes.

Data attributeValue
data-leve-file-upload-hidden-inputAlways present
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

ItemGroup#

No props of its own. Accepts all <ul> attributes.

Data attributeValue
data-leve-file-upload-item-groupAlways present
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Item#

PropDefaultType
file (required)–FileUploadFile

The file entry represented by this item.

Also accepts all <li> attributes.

Data attributeValue
data-leve-file-upload-itemAlways present
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

ItemName#

No props of its own. Accepts all <span> attributes.

Data attributeValue
data-leve-file-upload-item-nameAlways present

ItemSize#

No props of its own. Accepts all <span> attributes.

Data attributeValue
data-leve-file-upload-item-sizeAlways present

ItemDeleteTrigger#

No props of its own. Accepts all <button> attributes.

Data attributeValue
data-leve-file-upload-item-delete-triggerAlways present
data-disabledPresent when disabled or read-only

Accessibility#

  • Native elements: Uses <label for>, <button type="button"> for triggers and delete buttons, and a visually hidden <input type="file"> (tabIndex={-1}, aria-hidden="true").
  • Screen reader announcements: Announces file additions, removals, and rejections via a polite live region.
  • Accessible labels: FileUpload.ItemDeleteTrigger defaults aria-label to "Remove <filename>" when no aria-label is provided.
KeyElementAction
Enter / SpaceFileUpload.TriggerOpens the native file picker.
Enter / SpaceFileUpload.ItemDeleteTriggerRemoves the corresponding file item.