Skip to content

BbDropzone

A file field that takes files by drop or picker, validates them and hands you a File[], while upload state stays yours.

import { BbDropzone } from 'bitboss-ui';

On this page

Use it for

Use BbDropzone when the user hands you files: receipts, attachments, an avatar, an import.

Use something else when

  • useBbDropzone — a button opens the file picker and no field is needed, like a row's Replace
  • BbProgress — the task is showing an upload already in progress

Also see: Validated forms.

BbDropzone is the library's file field. It takes a label, hint and errors like every field, and its v-model is always a File[]. It captures and validates files; it does not upload them.

Passthrough

Hover or tap a part to outline it. The toggles turn on loading, errors and warnings where the component has them; only parts get a row.

Drop files here, or click to browse
Guidance while the control is focused.

Validate receipt attachments

Set accept, max-size and max-files, and turn every rejected file into a message the user can act on.

Drag receipts here

PNG, JPG or PDF · at most 3 files · 512 KB each

team-dinner.heic is not a receipt (PNG, JPG or PDF only).

No receipts attached yet.

Rejected files never enter the model. @error hands you every rejection of a drop or pick in one BbFileRejection[], after the model update (a drop that accepted nothing updates nothing). The field never fills errors itself: clear your messages on update:modelValue and set them on error (a size rejection's formattedSize is already in the app's locale).

One file or many

Bind a ref<File[]>([]). A pick or drop appends to it, and :max-files="1" makes a one-file field: read files[0].

PDF or DOCX, one file
Images or PDF, up to 5 files of 5 MB

Past max-files a new file is rejected, never swapped in. To replace the one file, empty the value first and then call the slot's open(). accept takes MIME types (application/pdf), wildcards (image/*), extensions (.pdf) or bare tokens (pdf, which covers both). Pair an explicit MIME type with its extension: a dropped file can arrive with an empty file.type.

Coming from v2multiple → max-files

multiple is gone and the value is always File[]. Replace ref<File | null>(null) with ref<File[]>([]) and read files[0]; a one-file field is :max-files="1". max-files="0" now takes nothing (leave it unset for no limit). DropZoneError is now BbFileRejection, and its maxFiles variant has no totalFiles.

Design the drop area

The default slot is the area, with no design of its own. A click anywhere in it opens the picker, except on a real button or link, so a Browse button calls open() itself.

Drag your invoices here

PDF or PNG · up to 10 MB

Paint the drop highlight from dragging and the library focus ring with :class="{ 'bb-ring': focused }". hide-label hides the label and keeps it as the name. Put labelId on one headline only (on a wrapper, hints and buttons join the name). For a field that is just a button, render <BbButton tag="span" :id="labelId">: it stays a single tab stop. Do not nest a <label> in the slot.

Coming from v2slot id removed

The slot's id (for your own <label for>) is gone: set the field's label. The area is a <div> and tag is gone; wrap the field for any other element.

Upload and submit

Inside a BbForm, give the field a name and build FormData from the files @submit hands you.

Sent with the Q2 pack

  • Q2 revenue review.pdf2.4 MB

Drag the Q3 PDFs here

PDF, listed below once added

Send with no new PDF and the form stops at the field, with the label in the required message. Outside a form, name renders the hidden input a native multipart post needs. Progress, cancellation, retry and server errors stay in your own state.

Coming from v2hidden input only with name

v2 always rendered the hidden submittable input; now it exists only when name is set.

Lock the field during an upload

Disable the field while an upload runs, so the selection cannot change mid-request.

Drag a .bin file here or click to choose

To show files nobody can change, such as a request sent for review, set readonly. A named read-only field still submits its files (disabled would not). Hide your remove and Browse buttons with the slot's readonly flag. There is no loading state: pair the transfer with BbProgress.

Open the picker from any button

useBbDropzone({ accept, maxSize, maxFiles }) opens the picker with a dropzone's rules and no field, and open() resolves with that pick.

  • Q2 revenue review.pdf2.4 MB
  • Supplier contract — Aeris.pdf795.8 KB

Call open() before any await (browsers open a picker only from the click), and empty files first: the handle keeps what it picked. To open a mounted field from elsewhere, give it an id and call useBbDropzone('that-id').open(). A value that joins a form or shows errors belongs in a BbDropzone.