Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    File Dropzone

    Drag and drop upload area on a native file input. Checks type, size, and count per file, lists files with icons, sizes, progress, and remove.

    • brand-guidelines.pdf2.3 MB
    • hero-photo.jpg1.1 MB
    • launch-video.mov46 MB
    • brand-guidelines.pdf2.3 MB
    • hero-photo.jpg1.1 MB
    • launch-video.mov46 MB
    • brand-guidelines.pdf 2.3 MB
    • hero-photo.jpg 1.1 MB
    • launch-video.mov 46 MB
    • brand-guidelines.pdf2.3 MB
    • hero-photo.jpg1.1 MB
    • launch-video.mov46 MB
    @php
        $files = [
            ['name' => 'brand-guidelines.pdf', 'size' => 2457600, 'type' => 'application/pdf', 'progress' => 100],
            ['name' => 'hero-photo.jpg', 'size' => 1153434, 'type' => 'image/jpeg', 'progress' => 64],
            ['name' => 'launch-video.mov', 'size' => 48234496, 'type' => 'video/quicktime', 'error' => 'Larger than 5 MB'],
        ];
    @endphp
    
    <x-markas.file-dropzone
        name="attachments[]"
        accept="image/*,.pdf"
        multiple
        :max-size="5242880"
        :max-files="4"
        hint="Images or PDF, up to 5 MB each"
        :files="$files"
    />
    import { FileDropzone } from "@/components/markas/FileDropzone";
    
    const files = [
      {
        name: "brand-guidelines.pdf",
        size: 2457600,
        type: "application/pdf",
        progress: 100,
      },
      { name: "hero-photo.jpg", size: 1153434, type: "image/jpeg", progress: 64 },
      {
        name: "launch-video.mov",
        size: 48234496,
        type: "video/quicktime",
        error: "Larger than 5 MB",
      },
    ];
    
    export default function FileDropzoneExample() {
      return (
        <FileDropzone
          name="attachments[]"
          accept="image/*,.pdf"
          multiple
          maxSize={5242880}
          maxFiles={4}
          hint="Images or PDF, up to 5 MB each"
          files={files}
        />
      );
    }
    <script setup lang="ts">
    import FileDropzone from "@/components/markas/FileDropzone.vue";
    
    const files = [
      {
        name: "brand-guidelines.pdf",
        size: 2457600,
        type: "application/pdf",
        progress: 100,
      },
      { name: "hero-photo.jpg", size: 1153434, type: "image/jpeg", progress: 64 },
      {
        name: "launch-video.mov",
        size: 48234496,
        type: "video/quicktime",
        error: "Larger than 5 MB",
      },
    ];
    </script>
    
    <template>
      <FileDropzone
        name="attachments[]"
        accept="image/*,.pdf"
        multiple
        :max-size="5242880"
        :max-files="4"
        hint="Images or PDF, up to 5 MB each"
        :files="files"
      />
    </template>
    <script lang="ts">
      import FileDropzone from "$lib/components/markas/FileDropzone.svelte";
    
      const files = [
        {
          name: "brand-guidelines.pdf",
          size: 2457600,
          type: "application/pdf",
          progress: 100,
        },
        {
          name: "hero-photo.jpg",
          size: 1153434,
          type: "image/jpeg",
          progress: 64,
        },
        {
          name: "launch-video.mov",
          size: 48234496,
          type: "video/quicktime",
          error: "Larger than 5 MB",
        },
      ];
    </script>
    
    <FileDropzone
      name="attachments[]"
      accept="image/*,.pdf"
      multiple
      maxSize={5242880}
      maxFiles={4}
      hint="Images or PDF, up to 5 MB each"
      {files}
    />
    ---
    import FileDropzone from "@/components/markas/FileDropzone.astro";
    
    const files = [
      {
        name: "brand-guidelines.pdf",
        size: 2457600,
        type: "application/pdf",
        progress: 100,
      },
      {
        name: "hero-photo.jpg",
        size: 1153434,
        type: "image/jpeg",
        progress: 64,
      },
      {
        name: "launch-video.mov",
        size: 48234496,
        type: "video/quicktime",
        error: "Larger than 5 MB",
      },
    ];
    ---
    
    <FileDropzone
      name="attachments[]"
      accept="image/*,.pdf"
      multiple
      maxSize={5242880}
      maxFiles={4}
      hint="Images or PDF, up to 5 MB each"
      files={files}
    />
    import { Component } from "@angular/core";
    import { FileDropzone } from "./markas/file-dropzone.component";
    
    @Component({
      selector: "markas-example",
      imports: [FileDropzone],
      template: `
        <markas-file-dropzone
          name="attachments[]"
          accept="image/*,.pdf"
          multiple
          [maxSize]="5242880"
          [maxFiles]="4"
          hint="Images or PDF, up to 5 MB each"
          [files]="files"
        />
      `,
    })
    export default class FileDropzoneExample {
      protected readonly files = [
        {
          name: "brand-guidelines.pdf",
          size: 2457600,
          type: "application/pdf",
          progress: 100,
        },
        { name: "hero-photo.jpg", size: 1153434, type: "image/jpeg", progress: 64 },
        {
          name: "launch-video.mov",
          size: 48234496,
          type: "video/quicktime",
          error: "Larger than 5 MB",
        },
      ];
    }

    Examples

    Single photo with custom labels

    Profile photo

    Shown on your profile and next to your comments.

    Profile photo

    Shown on your profile and next to your comments.

    • rania-portrait.png471 KB

    Profile photo

    Shown on your profile and next to your comments.

    • rania-portrait.png471 KB

    Profile photo

    Shown on your profile and next to your comments.

    • rania-portrait.png 471 KB

    Profile photo

    Shown on your profile and next to your comments.

    • rania-portrait.png471 KB

    Inside a form

    Attachments

    Attachments

    • campaign-brief.docx86 KB

    Attachments

    • campaign-brief.docx86 KB

    Attachments

    • campaign-brief.docx 86 KB

    Attachments

    • campaign-brief.docx86 KB

    Upload progress

    • keynote-deck.pdf5.6 MB
    • product-demo.mp440 MB
    • voiceover.wav9 MB
    • keynote-deck.pdf5.6 MB
    • product-demo.mp440 MB
    • voiceover.wav9 MB
    • keynote-deck.pdf 5.6 MB
    • product-demo.mp4 40 MB
    • voiceover.wav 9 MB
    • keynote-deck.pdf5.6 MB
    • product-demo.mp440 MB
    • voiceover.wav9 MB

    Installation

    npx markasui@latest add file-dropzone

    Usage

    <x-markas.file-dropzone
        name="attachments[]"
        accept="image/*,.pdf"
        multiple
        :max-size="5 * 1024 * 1024"
        :max-files="4"
        hint="Images or PDF, up to 5 MB each"
    />

    Needs Alpine.js. Inside a form with enctype="multipart/form-data" the valid files post as attachments[].

    Livewire

    <x-markas.file-dropzone multiple accept="image/*" :max-size="5242880" wire:model="photos" />

    Add use WithFileUploads; to the component. Only files that pass accept, maxSize, and maxFiles are uploaded, through a hidden file input that carries wire:model. Upload progress fills the bars, and removing every file sets the property back to null (or [] with multiple). Validate again on the server.

    import { FileDropzone } from "@/components/markas/FileDropzone";
    
    <FileDropzone
      accept="image/*,.pdf"
      multiple
      maxSize={5 * 1024 * 1024}
      maxFiles={4}
      hint="Images or PDF, up to 5 MB each"
      progress={progress}
      onFilesChange={upload}
    />;
    <template>
      <FileDropzone
        accept="image/*,.pdf"
        multiple
        :max-size="5 * 1024 * 1024"
        :max-files="4"
        hint="Images or PDF, up to 5 MB each"
        :progress="progress"
        @change="upload"
      />
    </template>
    <script lang="ts">
      import FileDropzone from "$lib/components/markas/FileDropzone.svelte";
    </script>
    
    <FileDropzone
      accept="image/*,.pdf"
      multiple
      maxSize={5 * 1024 * 1024}
      maxFiles={4}
      hint="Images or PDF, up to 5 MB each"
      {progress}
      onFilesChange={upload}
    />
    ---
    import FileDropzone from "@/components/markas/FileDropzone.astro";
    ---
    
    <FileDropzone
      name="attachments[]"
      accept="image/*,.pdf"
      multiple
      maxSize={5 * 1024 * 1024}
      maxFiles={4}
      hint="Images or PDF, up to 5 MB each"
    />

    A small custom element validates picks, keeps them on the native input, and dispatches a bubbling markas-change event with the valid files as detail. Show upload progress with dropzone.setProgress(name, percent).

    import { Component, signal } from "@angular/core";
    import { FileDropzone } from "./markas/file-dropzone.component";
    
    @Component({
      selector: "app-attachments",
      imports: [FileDropzone],
      template: `
        <markas-file-dropzone
          name="attachments[]"
          accept="image/*,.pdf"
          multiple
          [maxSize]="5242880"
          [maxFiles]="4"
          hint="Images or PDF, up to 5 MB each"
          [progress]="progress()"
          (filesChange)="upload($event)"
        />
      `,
    })
    export class Attachments {
      progress = signal<Record<string, number>>({});
      upload(files: File[]) {}
    }
    • The drop area is a label around a native file input, so a click, Enter, or Space opens the picker. Only valid files stay on the input, so a regular form post sends them.
    • Files that fail accept, maxSize, or maxFiles stay in the list with an error until removed.
    • files shows earlier uploads (name, size, type, progress, error). They are shown, not posted.
    • Progress: React and Vue take progress by file name. In Blade dispatch file-progress with { name, progress } on the component.
    • Attributes and class go to the outer element; name, accept, disabled, required, and id go to the input.

    Props

    NameTypeDefaultDescription
    namestring-Name of the native file input. The valid picked and dropped files post with the form, so use attachments[] with multiple.
    acceptstring-Allowed types, as in the accept attribute: .pdf, image/*, or application/zip, comma separated. Other files get the type error.
    multiplebooleanfalseKeeps adding files to the list. Without it a new pick replaces the file.
    maxSizenumber-Largest file in bytes, for example 5242880 for 5 MB. Larger files stay in the list with an error and are not posted.
    maxFilesnumber-Most valid files kept when multiple is on. Extra files get the too many error.
    files{ name, size, type?, progress?, error? }[][]Files already in the list, such as earlier uploads. They are shown but not posted.
    progressRecord<string, number>{}React and Vue: live upload progress by file name, 0 to 100. Blade: dispatch file-progress with { name, progress } on the component.
    hintstring-Small text under the prompt, such as PNG or JPG, up to 5 MB.
    disabled / required / idboolean / boolean / stringfalse / false / autoPassed to the native file input. Other attributes and class go to the outer element.
    onFilesChange / @change / files-change(files: File[]) => void-Called with the valid files after every add or remove. Blade dispatches a files-change event.
    dropLabelstringDrop files here orPrompt in the drop area, followed by browseLabel.
    browseLabelstringbrowseUnderlined word after the prompt.
    removeLabelstringRemove {name}Accessible name of each remove button. {name} is the file name.
    tooLargeLabelstringLarger than {size}Error for a file over maxSize. {size} is maxSize formatted, such as 5 MB.
    typeLabelstringFile type not allowedError for a file that does not match accept.
    tooManyLabelstringOnly {max} files allowedError for files past maxFiles. {max} is the limit.
    (filesChange)output<File[]>-Angular only. Emits the valid picked files every time the list changes. Svelte uses onFilesChange like React.
    markas-change / setProgress()CustomEvent<File[]> / method-Astro only. Bubbling event with the valid files as detail, and a method on markas-file-dropzone that shows upload progress for a file name.

    Accessibility

    • The drop area is a label around a visually hidden native file input, so a click, Enter, or Space opens the file picker and the prompt is its name.
    • Keyboard focus on the input outlines the whole drop area.
    • Each file error is a role alert, each progress bar is a role progressbar named after the file with aria-valuenow, and each remove button names the file.
    • With reduced motion the drop highlight and the icon lift appear without animation.

    Related components

    More markasui components with the same classes in every framework.