vael-ui v0.5.7

Forms & inputs

Layout

FileUpload

A drop zone and file list for picking files, with validation. Use it for attachments and uploads in forms.

Validating a form? vael-form wires this up with a schema

Install

import { FileUpload } from 'vael-ui'

Playground

Drop files here

    Placement, behaviour and animation

    Usage
    <script setup lang="ts">
    import { FileUpload } from 'vael-ui'
    </script>
    
    <template>
      <FileUpload />
    </template>

    Props

    NameTypeDefaultDescription
    acceptstringNative accept syntax: .pdf, image/png, image/*, comma-separated.
    captureboolean | "user" | "environment"Native capture: opens the camera instead of the picker on mobile. 'user'/'environment' pick the facing side; true lets the browser choose.
    multiplebooleantrueAccepts several files that add to the list. When false, a new file replaces the current one.
    maxSizenumberMaximum size per file, in bytes. Larger files fire @reject with 'maxSize'.
    maxFilesnumberMaximum number of files in the list. Files past it fire @reject with 'maxFiles'.
    disabledbooleanfalseDisables the dropzone, browse button and file input.
    namestringNative name on the file input.
    motionFileUploadMotiontrueHow file rows come and go. false adds and removes them at once. An object animates them your way: values for the item part ({ initial: { item: { opacity: 0, y: 6 } } }), stagger, or enter / leave hooks for your own library.
    uiPartial<Record<'root' | 'dropzone' | 'browse' | 'list' | 'item' | 'remove', UiPartValue>>Class and style overrides for each part.
    filesFile[][]Accepted files.

    Events

    NameTypeDescription
    add(files: File[])Fires with the files accepted from a pick, a drop or a paste.
    remove(file: File)Fires when you remove a file from the list.
    update:files(value: File[])Fires when files changes (v-model:files).
    reject({ file: File; reason: FileRejectReason; })Fires for each file that accept, maxSize or maxFiles rejects, with the reason.

    Slots

    NameTypeDescription
    default{ isDragOver: boolean; browse: () => void; }Custom dropzone content; the dropzone keeps its drag-and-drop handling. Receives isDragOver and browse.
    item{ file: File; remove: () => void; index: number; }Replaces one file row's content; the library keeps the <li>.

    Exposed

    NameTypeDescription
    elHTMLElement | nullRoot element.
    dropzoneElHTMLElement | nullDropzone element.
    inputElHTMLInputElement | nullNative file input.
    listElHTMLElement | nullFile list element (null until the first file is added).
    browse() => voidOpens the native file picker (no-op while disabled).

    Motion New

    FileUpload's rows: values or hooks for item, and the list's stagger and leaving.

    <FileUpload
      :motion="{ initial: { item: { opacity: 0, y: 8 } }, stagger: 0.04 }"
    />
    NameTypeDescription
    initialexititemSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
    enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
    staggerleavingappearnumber | 'pop' | 'hold' | booleanItems coming in together start stagger seconds apart. A leaving item lifts out so the rest close the gap ('pop'), or keeps its space until it's gone ('hold'). appear: true also brings in the items already there when it mounts.
    springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
    falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

    Accessibility

    KeyAction
    EnterSpaceOpens the file picker from the Browse button.
    EnterSpaceRemoves the file from its remove button.
    • The native file input is visually hidden and out of the tab order. The Browse button is the keyboard entry point; the drop zone isn’t focusable. Cmd or Ctrl with V pastes files while focus is inside it.
    • Each remove button is named “Remove” plus the file name. After a removal, focus moves to the next row’s button, the previous one, or the Browse button.
    • Rejected files are announced through a polite live region, such as “photo.png wasn’t added: it’s too large.”, and set aria-invalid.
    • Inside a Field, the Browse button reads the label, then “Browse files”, and the description and error describe it. Outside a Field, it reads “Browse files”.