File input
VFileInput selects files through a native dialog or drag and drop. The model is always a File[].
Usage
<script setup lang="ts">
import { ref } from 'vue'
import { VFileInput } from 'vectis-ui'
const files = ref<File[]>([])
</script>
<template>
<VFileInput v-model="files" label="Attachment" />
</template>Examples
Label and hint
Name the field with label. Use hint to describe accepted files.
<script setup lang="ts">
import { ref } from 'vue'
import { VFileInput } from 'vectis-ui'
import { search } from 'vectis-ui/icons'
const attachment = ref<File[]>([])
const found = ref<File[]>([
new File(['x'], 'contract.pdf', { type: 'application/pdf' }),
new File(['x'], 'annex.pdf', { type: 'application/pdf' }),
])
</script>
<template>
<div class="column">
<VFileInput
v-model="attachment"
label="Attachment"
hint="Drop a file on the field, or use the paperclip"
placeholder="No file chosen yet"
/>
<VFileInput
v-model="found"
multiple
display="chip"
:icon-start="search"
label="Search the attachments"
hint="An icon at the start, the paperclip at the end"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Sizes
size sets the field size.
<script setup lang="ts">
import { ref } from 'vue'
import { VFileInput } from 'vectis-ui'
const rows = ref(
(['sm', 'md', 'lg'] as const).map((size) => ({
key: size,
size,
label: size,
files: [] as File[],
})),
)
</script>
<template>
<div class="column">
<VFileInput
v-for="row in rows"
:key="row.key"
v-model="row.files"
:size="row.size"
:label="row.label"
multiple
display="chip"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Multiple files
multiple allows several files. Without it, extra files are rejected.
<script setup lang="ts">
import { ref } from 'vue'
import { VFileInput } from 'vectis-ui'
const one = ref<File[]>([])
const several = ref<File[]>([])
</script>
<template>
<div class="column">
<VFileInput
v-model="one"
label="One file, the default"
hint="Drop two and the second is turned away"
/>
<VFileInput
v-model="several"
multiple
display="chip"
counter
label="Several files"
hint="The model is a File array either way, so nothing downstream has to branch"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Clearable
clearable adds a button to empty the selection.
<script setup lang="ts">
import { ref } from 'vue'
import { VFileInput } from 'vectis-ui'
const withCross = ref<File[]>([])
const withoutCross = ref<File[]>([])
</script>
<template>
<div class="column">
<VFileInput
v-model="withCross"
clearable
multiple
display="chip"
label="Clearable"
hint="Add a file: the cross appears to the left of the paperclip"
/>
<VFileInput
v-model="withoutCross"
multiple
display="chip"
label="Not clearable, the default"
hint="Files then come out one chip at a time"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Display
With multiple files, display chooses comma-separated names or removable chips. A single file always appears as text.
<script setup lang="ts">
import { ref } from 'vue'
import { VChip, VFileInput } from 'vectis-ui'
import { description, picture_as_pdf as pictureAsPdf } from 'vectis-ui/icons'
const start = () => [
new File(['x'], 'quarterly-report.pdf', { type: 'application/pdf' }),
new File(['x'], 'balance-sheet-2026-final-v3.xlsx'),
]
const asText = ref(start())
const asChips = ref(start())
const custom = ref(start())
</script>
<template>
<div class="column">
<VFileInput
v-model="asText"
multiple
label="text, the default"
hint="The names joined by commas, on one line"
/>
<VFileInput
v-model="asChips"
multiple
display="chip"
label="chip"
hint="One dismissible chip each, cut in the middle so the extension survives"
/>
<VFileInput v-model="custom" multiple display="chip" label="a chip of your own">
<template #chip="{ file, label, remove, size }">
<VChip
:icon-start="file.type === 'application/pdf' ? pictureAsPdf : description"
:size="size"
:dismiss-label="`Remove ${file.name}`"
variant="outline"
tone="accent"
dismissible
@dismiss="remove"
>
{{ label }}
</VChip>
</template>
</VFileInput>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Per-file limits
accept filters file types and maxSize limits each file in bytes. Each refused file emits reject. Include extensions when MIME types may be missing.
<script setup lang="ts">
import { ref } from 'vue'
import { VFileInput, type FileRejection } from 'vectis-ui'
const files = ref<File[]>([])
const refused = ref<FileRejection[]>([])
const reasons: Record<string, string> = {
type: 'wrong kind of file',
size: 'too big on its own',
count: 'too many files',
'total-size': 'too much altogether',
}
function onReject(rejection: FileRejection) {
refused.value = [rejection, ...refused.value].slice(0, 4)
}
</script>
<template>
<div class="column">
<VFileInput
v-model="files"
accept="image/*,.pdf"
:max-size="500_000"
multiple
display="chip"
label="Receipts"
hint="Images and PDFs, 500 kB each at most"
@reject="onReject"
/>
<output v-if="refused.length" class="refused" aria-label="Files turned away">
<span v-for="item in refused" :key="item.file.name + item.reason">
{{ item.file.name }}: {{ reasons[item.reason] }}
</span>
</output>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-3);
max-inline-size: 26rem;
}
.refused {
display: grid;
gap: var(--vectis-space-1);
font-size: var(--vectis-text-body-sm-size);
color: var(--vectis-color-danger-text);
}
</style>Selection limits
maxFiles and maxTotalSize limit the whole selection, including existing files.
<script setup lang="ts">
import { ref } from 'vue'
import { VFileInput, type FileRejection } from 'vectis-ui'
const files = ref<File[]>([])
const refused = ref<FileRejection[]>([])
const reasons: Record<string, string> = {
type: 'wrong kind of file',
size: 'too big on its own',
count: 'that would be a fourth file',
'total-size': 'that would take the batch over 1 MB',
}
function onReject(rejection: FileRejection) {
refused.value = [rejection, ...refused.value].slice(0, 4)
}
</script>
<template>
<div class="column">
<VFileInput
v-model="files"
:max-files="3"
:max-total-size="1_000_000"
multiple
display="chip"
counter
clearable
label="Invoices"
hint="Three files at most, 1 MB altogether"
@reject="onReject"
/>
<output v-if="refused.length" class="refused" aria-label="Files turned away">
<span v-for="item in refused" :key="item.file.name + item.reason">
{{ item.file.name }}: {{ reasons[item.reason] }}
</span>
</output>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-3);
max-inline-size: 26rem;
}
.refused {
display: grid;
gap: var(--vectis-space-1);
font-size: var(--vectis-text-body-sm-size);
color: var(--vectis-color-danger-text);
}
</style>Counter
counter shows the file count and total size. Its slot receives text, count and bytes.
<script setup lang="ts">
import { ref } from 'vue'
import { VFileInput } from 'vectis-ui'
const start = () => [
new File([new Uint8Array(240_000)], 'quarterly-report.pdf', { type: 'application/pdf' }),
new File([new Uint8Array(96_000)], 'cover-photo.jpg', { type: 'image/jpeg' }),
]
const standard = ref(start())
const custom = ref(start())
</script>
<template>
<div class="column">
<VFileInput
v-model="standard"
counter
multiple
display="chip"
label="The counter as it comes"
hint="It sits under the field, to the right of this line"
/>
<VFileInput v-model="custom" counter multiple display="chip" label="A wording of your own">
<template #counter="{ count, bytes }">
<span class="own">{{ count }} of 5 · {{ Math.round(bytes / 1000) }} kB</span>
</template>
</VFileInput>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
.own {
font-variant-numeric: tabular-nums;
}
</style>Custom icon
Replace the file dialog icon with pickerIcon.
<script setup lang="ts">
import { ref } from 'vue'
import { VFileInput } from 'vectis-ui'
import { cloud_upload as cloudUpload, image } from 'vectis-ui/icons'
const documents = ref<File[]>([])
const photos = ref<File[]>([])
</script>
<template>
<div class="column">
<VFileInput
v-model="documents"
:picker-icon="cloudUpload"
multiple
display="chip"
label="Documents"
hint="pickerIcon takes the same values as every icon prop in the library"
/>
<VFileInput
v-model="photos"
:picker-icon="image"
accept="image/*"
multiple
display="chip"
label="Photos"
hint="Naming the icon after what the field accepts says more than a paperclip"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>States
readonly prevents selection and removal. noDrop disables only drag and drop. loading shows a spinner without disabling selection.
<script setup lang="ts">
import { ref } from 'vue'
import { VFileInput } from 'vectis-ui'
const chosen = () => [new File(['x'], 'contract.pdf', { type: 'application/pdf' })]
const invalid = ref(chosen())
const readOnly = ref(chosen())
const disabled = ref(chosen())
const noDrop = ref<File[]>([])
const uploading = ref(chosen())
</script>
<template>
<div class="column">
<VFileInput
v-model="invalid"
invalid
display="chip"
label="Invalid"
hint="For a rule of your own: nothing here is checked by the browser"
/>
<VFileInput
v-model="readOnly"
readonly
display="chip"
label="Read-only"
hint="What was chosen stays on show, and no dialog, drop or removal will change it"
/>
<VFileInput
v-model="disabled"
disabled
display="chip"
label="Disabled"
hint="Greyed through the colour tokens, and out of the tab order"
/>
<VFileInput
v-model="uploading"
loading
display="chip"
label="Uploading"
hint="A spinner where the paperclip was, and nothing else changes"
/>
<VFileInput
v-model="noDrop"
no-drop
multiple
display="chip"
label="Drop refused"
hint="The paperclip still opens the dialog: only dropping is turned away"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>API
Props
Events
Slots
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 type ChipSize = 'xs' | 'sm'
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