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

accept

Tells a file input which file types to offer, by extension or MIME type. It filters the picker but is only a hint; Vanilla Breeze's data-upload applies the same rules to dropped files.

Overview

accept lists the file types a file input expects. The operating system's picker uses it to filter what is shown, and on phones it decides whether to offer the camera, photo library or file browser. It does not validate: the user can usually switch the picker to "All files", and nothing stops a renamed file. Always check files on the server.

Applies to: <input type="file"> only.

Values

A comma-separated list of tokens. A file is offered if it matches any token. Matching is case-insensitive.

TokenMatches
.pdf, .docxFile names ending in that extension.
application/pdfFiles of that exact MIME type.
image/*, audio/*, video/*Any image, audio or video file.
Absent or emptyAny file (the default).

List both the extension and the MIME type when you can (.pdf,application/pdf). Operating systems differ in which they use to filter.

Examples

Camera capture on phones

With an image or video accept, the capture attribute asks a phone to open the camera directly: environment for the rear camera, user for the front. Desktop browsers ignore it.

Leave capture off when users may already have the photo; it can hide the photo library.

Checking type and size before upload

A quick client-side check saves a slow upload, but the server must repeat it.

Inside <form-field>, a custom validity message like this one is shown in the field's output.error.

In Vanilla Breeze

  • data-upload wraps a file input in a drop zone. Dropped files are checked against accept with the picker's rules (.ext against the name, type/* against the MIME family, anything else as an exact MIME type); files that don't match are left out and named in a polite status line. Without multiple, only the first accepted file is kept. The zone's prompt lists the accepted types in words: .pdf and application/pdf read "PDF", image/* reads "images" (data-label-images, -audio, -video translate the wildcard words), and other MIME types show as written (src/utils/upload-init.js).
  • Not the same as data-accept. data-accept is a keystroke filter for text inputs (data-accept="digits", "phone", "[0-9a-f]") that also sets a matching inputmode. It has nothing to do with files.
  • File input styling lives in src/native-elements/input/file.css; see <input>.

Accessibility

  • Say which types and sizes are allowed in visible hint text. Users can't see the filter until they open the picker, and a rejected file is frustrating to discover after choosing it.
  • A drop zone must not be the only way in. data-upload keeps the native input as the single, focusable control, so keyboard and screen-reader users can open the picker.

Security

  • accept is a convenience, not a control. Check the file's real type on the server from its contents, not its name or the browser-reported MIME type, and enforce size limits there.
  • Treat file names as untrusted text: escape them when you display them, and don't use them as storage paths.
  • Be careful with image/*: it includes SVG, which can contain script. Serve uploaded SVG with a restrictive Content-Type and Content-Security-Policy, or convert it, or list the raster types you want (image/png,image/jpeg,image/webp).

Browser support

accept works in every browser. capture works only in mobile browsers: Chrome for Android 25, Safari on iOS 10, Firefox for Android 79; desktop browsers ignore it.

Gotchas

  • Dragging a file onto a plain file input bypasses the picker's filter in some browsers. Use data-upload, which filters drops, or check in change.
  • MIME types for the same file differ between systems (a .csv may be text/csv, application/vnd.ms-excel or empty). Prefer extensions for document formats.

Related

Which to choose

  • accept — every file input with an expected type.
  • accept + data-upload — users will drag files in, or should see what they picked.
  • capture — the photo is taken there and then (a receipt, an ID document).
↑