Veil UI
Components

Upload Button

Opens the file picker from a styled button and reports selections.

Installation

$ npx veil-ui@latest add upload-button

Usage

import { UploadButton } from "@/components/ui/upload-button";

<UploadButton
  accept="image/*"
  multiple
  onFiles={(files) => upload(files)}
/>;

Examples

Basic

Images

Outline

API reference

PropTypeDefaultDescription
acceptstring—File type filter passed to the input.
multiplebooleanfalseAllow selecting more than one file.
onFiles(files: FileList) => void—Called with the selected files.
labelstring"Upload"Visible label when no children are given.
...propsButtonProps—All Button props and native button attributes.

Accessibility

  • The visible element is a real button named by its label or children.
  • The hidden file input is removed from the tab order; the button is the single keyboard stop.
  • Validate file type and size on the server, not only through accept.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add upload-button --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { Upload } from "lucide-vue-next";
import { ref } from "vue";

import { Button } from "@/components/ui/button";

defineOptions({ inheritAttrs: false });

const props = withDefaults(
  defineProps<{
    accept?: string;
    multiple?: boolean;
    onFiles?: (files: FileList) => void;
    label?: string;
    class?: string;
  }>(),
  { label: "Upload" },
);

const inputRef = ref<HTMLInputElement | null>(null);

function openPicker() {
  inputRef.value?.click();
}

function handleChange(event: Event) {
  const input = event.target as HTMLInputElement;
  const files = input.files;
  if (files && files.length > 0) props.onFiles?.(files);
  input.value = "";
}
</script>

<template>
  <input
    ref="inputRef"
    type="file"
    :accept="accept"
    :multiple="multiple"
    aria-hidden="true"
    tabindex="-1"
    class="sr-only"
    @change="handleChange"
  />
  <Button
    data-slot="upload-button"
    v-bind="$attrs"
    :class="props.class"
    @click="openPicker"
  >
    <Upload aria-hidden="true" />
    <slot>{{ label }}</slot>
  </Button>
</template>

On this page