Keyboard shortcut: Ctrl + K
Get started

File picker

VFilePicker is a drop zone with a native file dialog and an optional preview list. The model is always a File[].

Usage

vue
Drag your files herePDF or PNG, up to 5 MBor
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker } from 'vectis-ui'

const files = ref<File[]>([])
</script>

<template>
  <VFilePicker v-model="files" title="Drag your files here" subtitle="PDF or PNG, up to 5 MB" />
</template>

Examples

Title and subtitle

Use title for the instruction and subtitle for file constraints.

vue
Drop your files hereor
Drop your files hereImages or PDF, up to 5 MB eachor
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker } from 'vectis-ui'

const plain = ref<File[]>([])
const described = ref<File[]>([])
</script>

<template>
  <div class="column">
    <VFilePicker v-model="plain" title="Drop your files here" />

    <VFilePicker
      v-model="described"
      multiple
      accept="image/*,.pdf"
      :max-size="5_000_000"
      title="Drop your files here"
      subtitle="Images or PDF, up to 5 MB each"
    />
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
</style>

The list of files

preview="bottom" lists files below the zone. preview="end" places them beside it, moving below when the component is narrow.

vue
Listed under the zoneWhat a narrow form wants, there being no room beside itor
Listed beside the zoneNarrow the window and it folds back underneathor
Not listed, the defaultTwo files are held all the same: the value never depends on this propor
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { VFilePicker } from 'vectis-ui'

const under = ref<File[]>([])
const beside = ref<File[]>([])
const none = ref<File[]>([])

/* Create sample File objects after mounting for server rendering. */
onMounted(() => {
  const seed = () => [
    new File([new Uint8Array(320_000)], 'contract.pdf', { type: 'application/pdf' }),
    new File([new Uint8Array(48_000)], 'figures.csv', { type: 'text/csv' }),
  ]
  under.value = seed()
  beside.value = seed()
  none.value = seed()
})
</script>

<template>
  <div class="column">
    <div class="narrow">
      <VFilePicker
        v-model="under"
        multiple
        preview="bottom"
        title="Listed under the zone"
        subtitle="What a narrow form wants, there being no room beside it"
      />
    </div>

    <VFilePicker
      v-model="beside"
      multiple
      preview="end"
      title="Listed beside the zone"
      subtitle="Narrow the window and it folds back underneath"
    />

    <div class="narrow">
      <VFilePicker
        v-model="none"
        multiple
        title="Not listed, the default"
        subtitle="Two files are held all the same: the value never depends on this prop"
      />
    </div>
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
}
.narrow {
  max-inline-size: 26rem;
}
</style>

Custom icons

Customize the zone icon with icon and file-type icons with typeIcons.

vue
Drop your sources hereor
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { VFilePicker } from 'vectis-ui'
import { attach_file as attachFile, description } from 'vectis-ui/icons'

const files = ref<File[]>([])

/* Create sample File objects after mounting for server rendering. */
onMounted(() => {
  files.value = [
    new File([new Uint8Array(24_000)], 'styles.css', { type: 'text/css' }),
    new File([new Uint8Array(180_000)], 'assets.zip', { type: 'application/zip' }),
  ]
})
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="files"
      multiple
      preview="bottom"
      title="Drop your sources here"
      :icon="attachFile"
      :type-icons="{ code: description }"
    />
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
</style>

Thumbnails

Image files show thumbnails. hideThumbnails replaces them with file-type icons.

vue
Thumbnails, the defaultAn image is shown as itselfor
hideThumbnailsEvery file shows its kind insteador
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { VFilePicker } from 'vectis-ui'

const shown = ref<File[]>([])
const hidden = ref<File[]>([])

/* Generate a decodable PNG in the browser to demonstrate image thumbnails. */
async function gradientPng(name: string): Promise<File> {
  const canvas = document.createElement('canvas')
  canvas.width = 96
  canvas.height = 96
  const context = canvas.getContext('2d')
  if (!context) return new File([], name, { type: 'image/png' })
  const gradient = context.createLinearGradient(0, 0, 96, 96)
  gradient.addColorStop(0, '#6366f1')
  gradient.addColorStop(1, '#ec4899')
  context.fillStyle = gradient
  context.fillRect(0, 0, 96, 96)
  const blob = await new Promise<Blob | null>((resolve) => canvas.toBlob(resolve, 'image/png'))
  return new File(blob ? [blob] : [], name, { type: 'image/png' })
}

onMounted(async () => {
  const files = [
    await gradientPng('cover.png'),
    new File([new Uint8Array(90_000)], 'notes.pdf', { type: 'application/pdf' }),
  ]
  shown.value = files
  hidden.value = [...files]
})
</script>

<template>
  <div class="grid">
    <VFilePicker
      v-model="shown"
      multiple
      preview="bottom"
      title="Thumbnails, the default"
      subtitle="An image is shown as itself"
    />

    <VFilePicker
      v-model="hidden"
      multiple
      hide-thumbnails
      preview="bottom"
      title="hideThumbnails"
      subtitle="Every file shows its kind instead"
    />
  </div>
</template>

<style scoped>
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: var(--vectis-space-5);
}
</style>

Multiple files

multiple allows several files; maxFiles caps the selection.

vue
One fileDrop two and the second is refusedor
As many as you likemultiple, with nothing else to bound itor
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker, type FileRejection } from 'vectis-ui'

const one = ref<File[]>([])
const several = ref<File[]>([])

const refused = ref('')

function onReject({ file }: FileRejection) {
  refused.value = `${file.name} was turned away: this zone takes one file.`
}
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="one"
      preview="bottom"
      title="One file"
      subtitle="Drop two and the second is refused"
      @reject="onReject"
    />
    <p v-if="refused" class="value">{{ refused }}</p>

    <VFilePicker
      v-model="several"
      multiple
      preview="bottom"
      title="As many as you like"
      subtitle="multiple, with nothing else to bound it"
    />
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
.value {
  margin: 0;
  font-size: var(--vectis-text-body-sm-size);
  color: var(--vectis-color-danger-text);
}
</style>

Accepted kinds

accept filters both dialog selections and drops. Include file extensions when MIME types may be missing.

vue
Images and PDFBrowse and the dialog offers nothing else; drop and the rule is applied againor
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker, type FileRejection } from 'vectis-ui'

const files = ref<File[]>([])
const refused = ref('')

function onReject({ file }: FileRejection) {
  refused.value = `${file.name} was turned away: images and PDF only.`
}
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="files"
      multiple
      accept="image/*,.pdf"
      preview="bottom"
      title="Images and PDF"
      subtitle="Browse and the dialog offers nothing else; drop and the rule is applied again"
      @reject="onReject"
    />
    <p v-if="refused" class="value">{{ refused }}</p>
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
.value {
  margin: 0;
  font-size: var(--vectis-text-body-sm-size);
  color: var(--vectis-color-danger-text);
}
</style>

Maximum size

maxSize limits each file in bytes. Listen to reject to explain refusals.

vue
Up to 500 kB per fileEach file is weighed on its own, so a small one still gets throughor
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker, type FileRejection } from 'vectis-ui'

const files = ref<File[]>([])
const refused = ref('')

function onReject({ file }: FileRejection) {
  refused.value = `${file.name} was turned away: 500 kB at most per file.`
}
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="files"
      multiple
      :max-size="500_000"
      preview="bottom"
      title="Up to 500 kB per file"
      subtitle="Each file is weighed on its own, so a small one still gets through"
      @reject="onReject"
    />
    <p v-if="refused" class="value">{{ refused }}</p>
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
.value {
  margin: 0;
  font-size: var(--vectis-text-body-sm-size);
  color: var(--vectis-color-danger-text);
}
</style>

Total size and count

maxTotalSize limits the whole selection, including existing files.

vue
1 MB in all, three files at mostWhat is already in the list counts towards the totalor
<script setup lang="ts">
import { ref } from 'vue'
import { VFilePicker, type FileRejection } from 'vectis-ui'

const files = ref<File[]>([])
const refused = ref('')

function onReject({ file, reason }: FileRejection) {
  refused.value =
    reason === 'count'
      ? `${file.name} was turned away: three files at most.`
      : `${file.name} was turned away: 1 MB for the whole selection.`
}
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="files"
      multiple
      :max-total-size="1_000_000"
      :max-files="3"
      preview="bottom"
      title="1 MB in all, three files at most"
      subtitle="What is already in the list counts towards the total"
      @reject="onReject"
    />
    <p v-if="refused" class="value">{{ refused }}</p>
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
.value {
  margin: 0;
  font-size: var(--vectis-text-body-sm-size);
  color: var(--vectis-color-danger-text);
}
</style>

States

readonly prevents additions and removals while preserving focus. loading replaces the zone icon with a spinner without disabling selection.

vue
Read-onlyWhat was taken stays on show, its remove buttons disabled along with the zoneor
DisabledNo dialog, no drop, and the zone greys through the colour tokensor
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { VFilePicker } from 'vectis-ui'

const taken = ref<File[]>([])
const empty = ref<File[]>([])

onMounted(() => {
  taken.value = [
    new File([new Uint8Array(320_000)], 'contract.pdf', { type: 'application/pdf' }),
    new File([new Uint8Array(48_000)], 'figures.csv', { type: 'text/csv' }),
  ]
})
</script>

<template>
  <div class="column">
    <VFilePicker
      v-model="taken"
      multiple
      readonly
      preview="bottom"
      title="Read-only"
      subtitle="What was taken stays on show, its remove buttons disabled along with the zone"
    />

    <VFilePicker
      v-model="empty"
      disabled
      title="Disabled"
      subtitle="No dialog, no drop, and the zone greys through the colour tokens"
    />
  </div>
</template>

<style scoped>
.column {
  display: flex;
  flex-direction: column;
  gap: var(--vectis-space-5);
  max-inline-size: 26rem;
}
</style>

API

Props

PropTypeDefault
titlestringnone
Required drop instruction.
subtitlestringnone
Optional file constraints below the title.
iconIconSourcecloud_upload
Large icon in the drop zone.
hideBrowsebooleanfalse
Hides the browse button and makes the zone itself a button, activated with Enter or Space.
browseTextstringnone
Visible text and accessible name of the browse button. Defaults to the library dictionary.
previewFilePickerPreviewfalse | 'bottom' | 'end'false
Preview position: false, bottom or end. The side list moves below in narrow containers.
hideThumbnailsbooleanfalse
Uses file-type icons instead of image thumbnails.
typeIconsPartial<Record<FilePickerKind, IconSource>>none
Icon overrides by file kind.
removeIconIconSourceclose
Icon of the file removal button.
multiplebooleanfalse
Allows multiple files. Otherwise, extra files are rejected.
acceptstringnone
Accepted file types, using native syntax such as image/*,.pdf. Filters dialog selections and dropped files.
maxSizenumbernone
Maximum size per file, in bytes.
maxTotalSizenumbernone
Maximum total selection size, in bytes.
maxFilesnumbernone
Maximum number of selected files.
disabledbooleanfalse
Disables interaction.
readonlybooleanfalse
Prevents opening the dialog, dropping files and removing them. Controls remain focusable.
invalidbooleanfalse
Marks the control as invalid and applies the error style. Validate your file selection separately.
loadingbooleanfalse
Shows a spinner instead of the zone icon without disabling selection.
loadingTextstringnone
Loading text and accessible spinner name. Defaults to the library dictionary.
v-modelFile[][]
Selected files as a File[], even for a single file.

Events

EventType
change[files: File[]]
The selection changed. Receives the complete File[].
reject[rejection: FileRejection]
Emitted for each rejected file. Receives the file and a reason: type, size, count or total-size.
remove[file: File, index: number]
A file was removed. Receives the file and its index.

Slots

SlotType
icon{}
Zone illustration. Keep it non-interactive.
title{}
Instruction content. Use text and non-interactive inline elements.
subtitle{}
Constraint content. Use text and non-interactive inline elements.
browseFilePickerBrowseSlotProps
Custom browse control. Receives open and disabled; call open to show the dialog.
itemFilePickerRow
Entire preview row. Receives the file, index, kind, thumbnail, icon, formatted size and remove.
thumbnailFilePickerRow
Preview visual. Receives the same data as item.
removeFilePickerRemoveSlotProps
Removal control. Call remove and use removeLabel as its accessible name.

Types

Types used in the API tables. Import exported types from vectis-ui.

export interface BuiltinIcon {
  name: string
  paths: readonly [string] | readonly [string, string]
}
export interface FilePickerBrowseSlotProps {
  open: () => void
  disabled: boolean
}
export type FilePickerKind =
  | 'image'
  | 'pdf'
  | 'audio'
  | 'video'
  | 'archive'
  | 'spreadsheet'
  | 'code'
  | 'file'
export interface FilePickerRemoveSlotProps {
  file: File
  index: number
  remove: () => void
  removeLabel: string
}
export interface FilePickerRow {
  file: File
  index: number
  kind: FilePickerKind
  thumbnail: string | undefined
  icon: IconSource
  sizeText: string
  remove: () => void
}
export type FileRejectReason = 'type' | 'size' | 'count' | 'total-size'
export interface FileRejection {
  file: File
  reason: FileRejectReason
}
export type IconRender =
  | { path: string; viewBox?: string }
  | { component: Component; props?: Record<string, unknown> }
  | { src: string }
  | { text: string; class?: string }
  | { class: string }
export type IconSource = string | BuiltinIcon | IconRender

CSS variables

TokenValue
--vectis-control-size-file-picker-min-block10rem
--vectis-control-size-file-picker-icon2.5rem
--vectis-control-size-file-picker-thumb2.5rem