Skip to content

Commit 07bfc29

Browse files
authored
fix(form-file): fix drag and drop feature (bootstrap-vue#2169)
* fix(form-file): fix drag and drop feature adds missing handler registration, and adds optional drop placeholder. * Update README.md * Update README.md
1 parent 56c26da commit 07bfc29

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/components/form-file/README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ multiple files, and directory upload (for browsers that support directory mode)
77
<template>
88
<div>
99
<!-- Styled -->
10-
<b-form-file v-model="file" :state="Boolean(file)" placeholder="Choose a file..."></b-form-file>
10+
<b-form-file v-model="file"
11+
:state="Boolean(file)"
12+
placeholder="Choose a file..."
13+
drop-placeholder="Drop file here..."></b-form-file>
1114
<div class="mt-3">Selected file: {{file && file.name}}</div>
1215

1316
<!-- Plain mode -->
@@ -59,10 +62,16 @@ be relied for production.
5962

6063
Directory mode is not supported when the file input is in plain mode.
6164

62-
## Drag and Drop
65+
66+
## Drag and Drop support
6367
Drop mode is enabled by default. It can disabled by setting the `no-drop`
6468
prop. `no-drop`has no effect in plain mode.
6569

70+
You can optionally set a different placeholder while dragging via the
71+
`drop-placeholder` prop. The default is no drop placeholder text. Only
72+
plain text is supported. HTML and components are not supported. The
73+
`drop-placeholder` prop has no effect if `no-drop`is set or in `plain` mode,
74+
6675

6776
## Limiting to certain file types
6877
You can limit the file types by setting the `accept` prop to a string containing the
@@ -90,7 +99,7 @@ list of standard media types.
9099

91100
## Customize the placeholder text
92101
Use the prop `placeholder` to change the prompt text that is shown when no
93-
files are selected.
102+
files are selected. Only plain text is supported. HTML and components are not supported.
94103

95104

96105
## Customize browse button label
@@ -104,12 +113,13 @@ Also it is advised to use [:lang()](https://developer.mozilla.org/en-US/docs/Web
104113
```
105114

106115
Alternatively you can set the content of the custom file browe button
107-
text via the `browse-text` prop. Note, only plain text is supported. HTML or
108-
sub-components are not supported.
116+
text via the `browse-text` prop. Note, only plain text is supported. HTML and
117+
components are not supported.
109118

110119

111120
## Non custom file input
112121
You can have `<b-form-file>` render a browser native file input by setting the `plain` prop.
122+
Note that many of the customer form-file features do not apply when `plain` is set.
113123

114124

115125
## Contextual state feedback

src/components/form-file/form-file.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export default {
6363
{
6464
class: ['custom-file', 'b-form-file', this.stateClass],
6565
attrs: { id: this.safeId('_BV_file_outer_') },
66-
on: { dragover: this.dragover }
66+
on: {
67+
dragover: this.onDragover,
68+
dragleave: this.onDragleave,
69+
drop: this.onDrop
70+
}
6771
},
6872
[input, label]
6973
)
@@ -93,6 +97,10 @@ export default {
9397
type: String,
9498
default: null
9599
},
100+
dropPlaceholder: {
101+
type: String,
102+
default: null
103+
},
96104
multiple: {
97105
type: Boolean,
98106
default: false
@@ -112,6 +120,11 @@ export default {
112120
},
113121
computed: {
114122
selectLabel () {
123+
// Draging active
124+
if (this.dragging && this.dropPlaceholder) {
125+
return this.dropPlaceholder
126+
}
127+
115128
// No file choosen
116129
if (!this.selectedFile || this.selectedFile.length === 0) {
117130
return this.placeholder
@@ -203,7 +216,7 @@ export default {
203216
this.selectedFile = files[0]
204217
}
205218
},
206-
dragover (evt) {
219+
onDragover (evt) {
207220
evt.preventDefault()
208221
evt.stopPropagation()
209222
if (this.noDrop || !this.custom) {
@@ -212,12 +225,12 @@ export default {
212225
this.dragging = true
213226
evt.dataTransfer.dropEffect = 'copy'
214227
},
215-
dragleave (evt) {
228+
onDragleave (evt) {
216229
evt.preventDefault()
217230
evt.stopPropagation()
218231
this.dragging = false
219232
},
220-
drop (evt) {
233+
onDrop (evt) {
221234
evt.preventDefault()
222235
evt.stopPropagation()
223236
if (this.noDrop) {

0 commit comments

Comments
 (0)