Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

data-upload

Turn a native file input into a drag-and-drop zone with a file list. Dropped files follow the input's accept and multiple rules; rejected files are announced.

Overview

data-upload wraps a native <input type="file"> in a drop zone that lists the chosen files by name and size. The input stays the real control: it is stretched transparently over the zone, so a click anywhere opens the file picker, it keeps the only tab stop, and it submits with the form.

Dropped files follow the same rules as the picker: the native accept attribute filters them and, without multiple, only the first file is kept. Anything left out is announced in a status line.

Usage

After setup the input sits inside this structure (the script builds it; you do not write it):

Options

AttributeValuesDefaultEffect
data-uploadboolean—Builds the drop zone around the file input.
acceptnative: .ext, type/*, type/subtypeany fileFilters the picker and dropped files. Shown under the prompt (".pdf,.doc" reads "PDF, DOC"). Matching is case-insensitive.
multiplenative booleanoffAllows several files. Without it a drop keeps only the first accepted file. Also switches the default prompt to "Drag files here or".
data-label-promptstring"Drag a file here or" / "Drag files here or"Prompt text before the browse cue.
data-label-browsestring"browse"The underlined browse cue.
data-label-filesstring"Selected files"Accessible name of the file list.
data-label-rejectedstring, {files}"Not accepted: {files}"Status text when dropped files do not match accept.
data-label-singlestring, {file}"Only one file allowed. Kept {file}."Status text when several files are dropped on an input without multiple.
data-label-images, data-label-audio, data-label-videostring"images" / "audio" / "video"Words for image/*, audio/* and video/* in the accept hint. Extensions and exact types show as written (.pdf and application/pdf both read "PDF").

The data-label-* attributes go on the input. File sizes are formatted with Intl.NumberFormat in the language of the closest [lang], using decimal units (1 kB = 1000 bytes).

Behaviour

  • Selection replaces — each pick or drop replaces the previous selection, as the native input does. A drop where every file is rejected leaves the current selection alone.
  • Drag state — data-dragover is set on .upload-zone while files are dragged over it.
  • Reset — a form reset empties the file list and the status line.
  • Disabled — a disabled input ignores drops and the zone is dimmed.
  • No size or count limits — the script does not check file size or count. Enforce limits in your own change handler (with setCustomValidity) and on the server. accept is a hint the user can bypass; always validate type on the server too.

Events

No custom events. Picking files fires the native input and change events; a drop that accepts at least one file fires both too, after updating input.files.

Styling

No custom properties. Style the generated classes; these are the shipped rules that matter most:

Other hooks: .upload-prompt (and its small), .upload-file-list li, .upload-file-name, .upload-file-size. In forced-colours mode the focus outline and the drag border use Highlight.

Accessibility

  • The native file input is the only control and the only tab stop. Its <label> names it; give it a visible one.
  • Keyboard focus on the input draws an outline around the whole zone. Enter or Space opens the picker, as on any file input.
  • The prompt, including the accepted types, is linked to the input with aria-describedby.
  • The browse cue is plain text, not a second button.
  • Rejected and dropped-extra files are announced through the role="status" line, which is also visible.
  • The file list is a labelled <ul> ("Selected files").
  • Drag and drop is never required: everything a drop does, the picker does too.
  • Without JavaScript the native file input renders as normal.

Examples

Accepted types

Try dropping a file of another type: it is left out and named in the status line.

Multiple files and reset

Localized

Strings come from data-label-*; sizes follow lang="de" ("1,5 kB").

Related

  • <input type="file"> — the native control, with accept, multiple and capture.
  • <form-field> — label, hint and validation messages.
  • File display pattern — [data-file] rows and cards for files shown outside the drop zone, such as uploads already on the server.
  • data-accept — a character filter for text inputs; it does not limit file types. Use the native accept attribute for that.
  • accept — the file-type filter data-upload also applies to dropped files.
  • multiple — one file or many.
↑