Skip to content

Commit 3c606ed

Browse files
tag instead of element (issue #520)
1 parent e13e32e commit 3c606ed

File tree

9 files changed

+36
-35
lines changed

9 files changed

+36
-35
lines changed

example/components/handle.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77
<div class="col-7">
88
<h3>Draggable {{ draggingInfo }}</h3>
99

10-
<draggable
11-
element="ul"
12-
:list="list"
13-
class="list-group"
14-
handle=".handle"
15-
>
10+
<draggable tag="ul" :list="list" class="list-group" handle=".handle">
1611
<li
1712
class="list-group-item"
1813
v-for="(element, idx) in list"

example/components/infra/nested.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
2-
<draggable class="dragArea" :element="'ul'" :list="tasks" :group="{ name: 'g1' }">
2+
<draggable class="dragArea" tag="ul" :list="tasks" :group="{ name: 'g1' }">
33
<li v-for="el in tasks" :key="el.name">
44
<p>{{ el.name }}</p>
5-
<nested-draggable :tasks="el.tasks"/>
5+
<nested-draggable :tasks="el.tasks" />
66
</li>
77
</draggable>
88
</template>

example/components/simple.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
<input
1616
id="disabled"
1717
type="checkbox"
18-
v-model="disabled"
18+
v-model="enabled"
1919
class="form-check-input"
2020
/>
21-
<label class="form-check-label" for="disabled">Disable DnD</label>
21+
<label class="form-check-label" for="disabled">DnD enabled</label>
2222
</div>
2323
</div>
2424
</div>
@@ -28,7 +28,7 @@
2828

2929
<draggable
3030
:list="list"
31-
:disabled="disabled"
31+
:disabled="!enabled"
3232
class="list-group"
3333
@start="dragging = true"
3434
@end="dragging = false"
@@ -59,7 +59,7 @@ export default {
5959
},
6060
data() {
6161
return {
62-
disabled: false,
62+
enabled: true,
6363
list: [
6464
{ name: "John", id: 0 },
6565
{ name: "Joao", id: 1 },

example/components/table-column-example..vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
<table class="table table-striped">
77
<thead class="thead-dark">
8-
<draggable v-model="headers" element="tr">
9-
<th v-for="header in headers" :key="header" scope="col">{{ header }}</th>
8+
<draggable v-model="headers" tag="tr">
9+
<th v-for="header in headers" :key="header" scope="col">
10+
{{ header }}
11+
</th>
1012
</draggable>
1113
</thead>
1214
<tbody>
@@ -17,9 +19,9 @@
1719
</table>
1820
</div>
1921

20-
<rawDisplayer class="col-2" :value="list" title="List"/>
22+
<rawDisplayer class="col-2" :value="list" title="List" />
2123

22-
<rawDisplayer class="col-2" :value="headers" title="Headers"/>
24+
<rawDisplayer class="col-2" :value="headers" title="Headers" />
2325
</div>
2426
</template>
2527

example/components/table-example.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<th scope="col">Sport</th>
1212
</tr>
1313
</thead>
14-
<draggable v-model="list" :element="'tbody'">
14+
<draggable v-model="list" tag="tbody">
1515
<tr v-for="item in list" :key="item.name">
1616
<td scope="row">{{ item.id }}</td>
1717
<td>{{ item.name }}</td>

example/components/third-party.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</h3>
1212

1313
<draggable
14-
element="el-collapse"
14+
tag="el-collapse"
1515
:list="list"
1616
:component-data="collapseComponentData"
1717
>

example/components/transition-example-2.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<h3>Transition</h3>
1111
<draggable
1212
class="list-group"
13-
element="ul"
13+
tag="ul"
1414
v-model="list"
1515
v-bind="dragOptions"
1616
@start="drag = true"

example/components/transition-example.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<h3>Transition</h3>
1111
<draggable
1212
class="list-group"
13-
element="ul"
13+
tag="ul"
1414
v-model="list"
1515
v-bind="dragOptions"
1616
@start="isDragging = true"

src/vuedraggable.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ const props = {
103103
type: String,
104104
default: "div"
105105
},
106+
tag: {
107+
type: String,
108+
default: null
109+
},
106110
move: {
107111
type: Function,
108112
default: null
@@ -163,7 +167,7 @@ const draggableComponent = {
163167
update("on", on);
164168
update("props", props);
165169
}
166-
return h(this.element, attributes, children);
170+
return h(this.getTag(), attributes, children);
167171
},
168172

169173
created() {
@@ -173,6 +177,10 @@ const draggableComponent = {
173177
);
174178
}
175179

180+
if (this.element !== "div") {
181+
console.warn("Element props is deprecated please use tag props instead.");
182+
}
183+
176184
if (this.options !== undefined) {
177185
console.warn(
178186
"Options props is deprecated, add sortable options directly as vue.draggable item, or use v-bind."
@@ -182,12 +190,10 @@ const draggableComponent = {
182190

183191
mounted() {
184192
this.noneFunctionalComponentMode =
185-
this.element.toLowerCase() !== this.$el.nodeName.toLowerCase();
193+
this.getTag().toLowerCase() !== this.$el.nodeName.toLowerCase();
186194
if (this.noneFunctionalComponentMode && this.transitionMode) {
187195
throw new Error(
188-
`Transition-group inside component is not supported. Please alter element value or remove transition-group. Current element value: ${
189-
this.element
190-
}`
196+
`Transition-group inside component is not supported. Please alter tag value or remove transition-group. Current tag value: ${this.getTag()}`
191197
);
192198
}
193199
var optionsAdded = {};
@@ -199,17 +205,11 @@ const draggableComponent = {
199205
optionsAdded["on" + elt] = emit.bind(this, elt);
200206
});
201207

202-
const options = Object.assign(
203-
{},
204-
this.options,
205-
this.$attrs,
206-
optionsAdded,
207-
{
208-
onMove: (evt, originalEvent) => {
209-
return this.onDragMove(evt, originalEvent);
210-
}
208+
const options = Object.assign({}, this.options, this.$attrs, optionsAdded, {
209+
onMove: (evt, originalEvent) => {
210+
return this.onDragMove(evt, originalEvent);
211211
}
212-
);
212+
});
213213
!("draggable" in options) && (options.draggable = ">*");
214214
this._sortable = new Sortable(this.rootContainer, options);
215215
this.computeIndexes();
@@ -250,6 +250,10 @@ const draggableComponent = {
250250
},
251251

252252
methods: {
253+
getTag() {
254+
return this.tag || this.element;
255+
},
256+
253257
getIsCloning() {
254258
const { group } = this.$attrs;
255259
const groupConsideringOption = group || this.getOptionGroup();

0 commit comments

Comments
 (0)