Basic Usage
<template>
<NbFileUploader
heading="Upload files"
description="Max file size is 500 KB. Supported file types are .jpg, .png, and .pdf."
button-label="Add file"
accept=".jpg,.png,.pdf"
:max-size="512000"
/>
</template>Variants
The variant prop sets the accent color on the button and the drag-over drop zone. Every NbButton variant is supported.
<template>
<NbFileUploader variant="primary" button-label="Add file" />
<NbFileUploader variant="danger" button-label="Add file" />
<NbFileUploader variant="success" button-label="Upload" />
</template>Multiple Files
Set multiple to allow selecting more than one file at a time.
<template>
<NbFileUploader multiple button-label="Add files" />
</template>File States
Each file in the list can be in one of three states, controlled via the setFileStatus method on the component instance:
| State | Visual |
|---|---|
idle | Filename with X to remove |
loading | Animated spinner (no remove button) |
success | Filled checkmark icon |
Validation errors (size, type) are shown immediately on drop/select with a red border and error message below the filename.
<template>
<NbFileUploader ref="uploader" button-label="Add file" :max-size="512000" />
</template>// After starting your upload request:
uploader.value.setFileStatus(0, 'loading')
// On success:
uploader.value.setFileStatus(0, 'success')
// On server-side error:
uploader.value.setFileStatus(0, 'idle', 'Upload failed. Please try again.')Validation
Client-side validation runs automatically on file select and drop:
- maxSize - rejects files larger than the specified number of bytes.
- accept - rejects files whose extension does not match the accept string.
Rejected files are still added to the list with an error state so the user can see what went wrong and remove them.
<template>
<NbFileUploader accept=".jpg,.png" :max-size="204800" />
</template>Disabled
Set disabled while the files cannot be taken, for instance while a form is saving. The trigger and the hidden file input are disabled, so neither a click nor the keyboard opens the picker, and Tab skips the trigger. Dragging a file over the component shows no drop zone and a not-allowed cursor, and a drop is ignored. Files already in the list stay, and their remove buttons are disabled too, so the list cannot change until the uploader is enabled again.
The trigger takes the disabled look of every NbButton, and the heading, description and file list dim to the opacity disabled fields use.
<template>
<NbFileUploader heading="Upload files" :disabled="saving" />
</template>Events
| Event | Payload | Description |
|---|---|---|
change | File[] | Emitted after any file add or remove (valid files only) |
remove | File | Emitted when a file is removed from the list |
<template>
<NbFileUploader @change="onFilesChanged" @remove="onFileRemoved" />
</template>Props
| Prop | Type | Default | Description |
|---|---|---|---|
heading | string | - | Bold heading above the component |
description | string | - | Helper text with a left border accent |
buttonLabel | string | 'Add file' | Label for the upload trigger button |
variant | 'primary' | 'secondary' | 'ghost' | 'danger' | 'success' | 'warning' | 'primary' | Accent color from NbButton variants |
accept | string | - | Native accept attribute (e.g. .jpg,.pdf) |
multiple | boolean | false | Allow selecting multiple files |
maxSize | number | - | Max file size in bytes for client validation |
disabled | boolean | false | Ignore clicks, the keyboard and drops |
Exposed
| Name | Type | Description |
|---|---|---|
files | Ref<FileItem[]> | Reactive list of file items |
setFileStatus | (index, status, error?) => void | Programmatically update a file's state |