Upload
The Upload input component uses HTML's native file input. It allows users to select files from their device for upload. In addition to native input features, it adds support for Drag and drop and clearing the input. Use it with the Field component to access all the functionalities.
Examples
Base
Show code
html
<section>
<o-field>
<o-upload v-slot="{ onclick }" v-model="file">
<o-button tag="button" variant="primary" @click="onclick">
<o-icon icon="upload" />
<span>Click to upload</span>
</o-button>
</o-upload>
</o-field>
<p><b>Selected:</b> {{ file?.name }}</p>
</section>
javascript
import { ref } from "vue";
const file = ref<File>();
Drag&Drop
Enable drag and drop using the drag-drop prop. To allow multiple files to be uploaded, set the multiple prop.
Show code
html
<section>
<o-field>
<o-upload v-model="dropFiles" multiple drag-drop>
<div style="text-align: center">
<p>
<o-icon icon="upload" size="is-large" />
</p>
<p>Drop your files here or click to upload</p>
</div>
</o-upload>
</o-field>
<div class="tags">
<span v-for="(file, index) in dropFiles" :key="index">
{{ file.name }}
<o-button
icon-left="times"
size="small"
native-type="button"
@click="deleteDropFile(index)">
</o-button>
</span>
</div>
</section>
javascript
import { ref } from "vue";
const dropFiles = ref<File[]>([]);
function deleteDropFile(index): void {
dropFiles.value.splice(index, 1);
}
Disabled
Prevent inputs with the disabled prop.
Show code
html
<section>
<o-field>
<o-upload disabled>
<o-button tag="button" variant="primary">
<o-icon icon="upload" />
<span>Click to upload</span>
</o-button>
</o-upload>
</o-field>
<o-field>
<o-upload drag-drop disabled>
<div style="text-align: center">
<p>
<o-icon icon="upload" size="is-large" />
</p>
<p>Drop your files here or click to upload</p>
</div>
</o-upload>
</o-field>
</section>
Variants
Different styles can be achieved with the variant prop.
Show code
html
<section>
<o-field label="Primary">
<o-upload v-model="file" drag-drop variant="primary" expanded>
<div style="text-align: center">
<o-icon icon="upload" /> Hover to see color variant
</div>
</o-upload>
</o-field>
<o-field label="Secondary">
<o-upload v-model="file" drag-drop variant="secondary" expanded>
<div style="text-align: center">
<o-icon icon="upload" /> Hover to see color variant
</div>
</o-upload>
</o-field>
<o-field label="Success">
<o-upload v-model="file" drag-drop variant="success" expanded>
<div style="text-align: center">
<o-icon icon="upload" /> Hover to see color variant
</div>
</o-upload>
</o-field>
<o-field label="Info">
<o-upload v-model="file" drag-drop variant="info" expanded>
<div style="text-align: center">
<o-icon icon="upload" /> Hover to see color variant
</div>
</o-upload>
</o-field>
<o-field label="Warning">
<o-upload v-model="file" drag-drop variant="warning" expanded>
<div style="text-align: center">
<o-icon icon="upload" /> Hover to see color variant
</div>
</o-upload>
</o-field>
<o-field label="Danger">
<o-upload v-model="file" drag-drop variant="danger" expanded>
<div style="text-align: center">
<o-icon icon="upload" /> Hover to see color variant
</div>
</o-upload>
</o-field>
<p><b>Selected:</b> {{ file?.name }}</p>
</section>
javascript
import { ref } from "vue";
const file = ref<File>();
Upload Component
Upload one or more files.
html
<o-upload></o-upload>Props
| Prop name | Description | Type | Values | Default |
|---|---|---|---|---|
| accept | Same as native accept | string | - | |
| customValidity | Custom HTML 5 validation error to set on the form control | string | ((currentValue: UploadType<unknown, IsMultiple> | null , state: ValidityState) => string) | undefined | - | "" |
| disabled | Same as native disabled | boolean | - | false |
| dragDrop | Accepts drag & drop and change its style | boolean | - | false |
| expanded | Upload will be expanded (full-width) | boolean | - | From config: upload: { |
| v-model | The input value state | File | object | - | |
| multiple | Same as native, also push new item to v-model instead of replacing | IsMultiple | - | |
| native | Replace last chosen files every time (like native file input element) | boolean | - | true |
| override | Override existing theme classes completely | boolean | - | |
| useHtml5Validation | Enable HTML 5 native validation | boolean | - | From config: { |
| variant | Color variant of the control | string | primary, info, success, warning, danger, and any other custom color | From config: upload: { |
Events
| Event name | Properties | Description |
|---|---|---|
| update:model-value | value object | object[] | File | File[] - updated modelValue prop | modelValue prop two-way binding |
| focus | event Event - native event | on input focus event |
| blur | event Event - native event | on input blur event |
| invalid | event Event - native event | on input invalid event |
Slots
| Name | Description | Bindings |
|---|---|---|
| default | Default content | onclick (event: Event): void - click handler, only needed if a button is used |
Class Inspector
Want to know how does the Class Inspector work?
| Class prop | Description | Props | Suffixes | |
|---|---|---|---|---|
| rootClass | Class of the root element. | |||
| expandedClass | Class of the root element when expanded. | expanded | ||
| disabledClass | Class of the root element when disabled. | disabled | ||
| variantClass | Class of the root element with variant. 👉 Drag & drop a file to see it in action! | variant | primary | |
| draggableClass | Class of the dragable container element. | dragDrop | ||
| draggableHoveredClass | Class of the dragable container element when hovered. 👉 Drag & drop a file to see it in action! | dragDrop |
Sass Variables
Current theme ➜ Oruga
| SASS Variable | Default |
|---|---|
| $upload-draggable-padding | calc(4 * h.useVar("control-spacer")) |
| $upload-disabled-opacity | h.useVar("control-disabled-opacity") |
| $upload-draggable-background-color | h.useVar( "control-background-color") |
| $upload-draggable-border-color | h.useVar("control-border-color") |
| $upload-draggable-border-style | dashed |
| $upload-draggable-border-radius | h.useVar("border-radius") |
| $upload-draggable-border-width | h.useVar("control-border-width") |
| $upload-draggable-hover-border-color | h.useVar("secondary") |
| $upload-draggable-hover-background-color | h.useVar( "control-background-color") |
See ➜ 📄 SCSS file
Current theme ➜ Bulma
| SASS Variable | Default |
|---|---|
| $upload-bg | transparent |
| $upload-draggable-padding | 2em |
| $upload-colors | file.$file-colors |
| $upload-border-color | css.getVar("grey-light") |
See ➜ 📄 SCSS file
Current theme ➜ Bootstrap
| SASS Variable | Default |
|---|---|
| $upload-draggable-bg | transparent |
| $upload-draggable-bg-hover | transparent |
| $upload-draggable-border-color | var(--#{$prefix}border-color) |
| $upload-draggable-border-color-hover | var(--#{$prefix}dark-bg-subtle) |
| $upload-draggable-border-width | var(--#{$prefix}border-width) |
| $upload-draggable-border-radius | var(--#{$prefix}border-radius) |
| $upload-draggable-padding | 2em |
| $upload-disabled-opacity | 0.5 |
See ➜ 📄 SCSS file
