Skip to content
Nana UI

Forms & Inputs

Dropzone

Where files are dropped or picked — a signed lease, photographs of a meter, a bank statement. It checks each file against accept, max-size and max-files as it arrives, keeps those that pass and says plainly why the others were turned away.

View .md Download

The kept files submit with the form under name. Show them with nana-file, listening for nana-change, and call removeFile() when one is taken out.

The zone is a button: Enter or Space opens the file browser, so it works without a mouse.

Drop a PDF or a photograph, or press the zone to browse. Anything larger than 5 MB, or of another type, is turned away with the reason.

Meter photographs
Drop files here or browse image files, PDF · up to 10 MB · 3 files at most
npm install @nana-tec/ui-components

Or copy the source in and own it:

npx @nana-tec/ui add dropzone --framework web-components
npx @nana-tec/ui add dropzone --framework svelte

Lands in src/lib/components/ui/dropzone/ as NanaDropzone.svelte, styled with Tailwind classes that resolve to the design tokens. Requires Tailwind v4.

Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and each component downloads only the first time a page uses it:

import "@nana-tec/ui-components/autoloader";
import "@nana-tec/ui-components/theme";

The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.

Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:

import "@nana-tec/ui-components/dropzone";

Copied in with npx @nana-tec/ui add dropzone? Import your project's own @/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.

<nana-dropzone label="Signed lease" name="lease" accept=".pdf" max-size="10485760"></nana-dropzone>
const el = document.querySelector("nana-dropzone");
el.addEventListener("nana-change", (e) => console.log(e.detail));
<script lang="ts">
import { NanaDropzone } from '$lib/components/ui/dropzone';
let files = $state<File[]>([]);
</script>
<NanaDropzone label="Signed lease" name="lease" accept=".pdf" maxSize={10_485_760} bind:files />

Each file is checked against accept, maxSize and maxFiles as it arrives; those that pass are kept in files, and the zone says plainly why any others were turned away. The kept files submit with the form under name. Remove one by writing files without it. The zone is a button: Enter or Space opens the file browser.

Properties

PropertyAttributeTypeDefaultDescription
acceptacceptstring''File types to take, as on <input type="file">: .pdf, image/*, application/pdf
disableddisabledbooleanfalseBlocks dropping and browsing.
helperTexthelper-textstring''Help below the zone
invalidinvalidbooleanfalseMarks the drop area invalid.
labellabelstring''Label above the zone
maxFilesmax-filesnumber | undefined—Most files to hold at once
maxSizemax-sizenumber | undefined—Largest file to take, in bytes
multiplemultiplebooleanfalseTake more than one file
namenamestring''Name the value is submitted under in a form.
requiredrequiredbooleanfalseThe form will not submit while this has no value.
valuevaluestring—The names of the kept files; set it to '' to clear them

Methods

MethodDescription
addFiles(files: Iterable<File>): voidOffer files as if they had been dropped
browse(): voidOpen the file browser
clear(): voidTake every file out
removeFile(file: File): voidTake a file out

Events

EventDescription
nana-changeThe kept files changed (detail.files, and detail.rejected for any turned away)

Slots

SlotDescription
(default)The prompt inside the zone

CSS parts

PartDescription
::part(base)The field
::part(zone)The area files are dropped on
::part(hint)The line naming what is accepted
::part(errors)The reasons files were turned away
::part(label)The label
::part(req)The required marker
::part(icon)The icon
::part(prompt)The prompt
::part(browse)The browse
::part(help)The help
::part(error)One reason a file was turned away

CSS custom properties

PropertyDescription
--nana-dropzone-accentThe colour of the zone while a file is over it
--nana-dropzone-bgThe zone's background

NanaDropzone

PropTypeDefault
filesbind:File[][]
namestring
acceptstring''
multiplebooleanfalse
maxSizenumber
maxFilesnumber
labelstring
helperTextstring
requiredbooleanfalse
disabledbooleanfalse
childrenSnippet
onFilesChange(files: File[], rejected: DropzoneRejected[]) => void

Also accepts Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children'>.