Skip to content

Commit 01d9f40

Browse files
committed
fix: dropping items not on top of another item wouldn't trigger an update
1 parent 7a01bbc commit 01d9f40

File tree

3 files changed

+49
-25
lines changed

3 files changed

+49
-25
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.vue

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,48 @@
1-
<script setup lang="ts">
2-
// This starter template is using Vue 3 <script setup> SFCs
3-
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
1+
<script lang="ts" setup>
2+
import { reactive } from "vue";
3+
import DraggableList from "./components/DraggableList.vue";
4+
5+
const testArray = reactive([
6+
{
7+
id: 1,
8+
name: "Bob"
9+
},
10+
{
11+
id: 2,
12+
name: "Alice"
13+
},
14+
{
15+
id: 3,
16+
name: "Lisa"
17+
}
18+
]);
19+
20+
const onStart = (...args) => {
21+
console.log("On start", args);
22+
};
23+
24+
const onEnd = (...args) => {
25+
console.log("On end", args);
26+
};
27+
28+
const onUpdate = (...args) => {
29+
console.log("On update", args);
30+
};
431
</script>
532

633
<template>
7-
<div>
8-
<a href="https://vitejs.dev" target="_blank">Vite</a>
9-
<a href="https://vuejs.org/" target="_blank">Vue</a>
10-
</div>
34+
<h1>Example</h1>
35+
<DraggableList
36+
item-key="id"
37+
v-model:list="testArray"
38+
@start="onStart"
39+
@end="onEnd"
40+
@update="onUpdate"
41+
>
42+
<template #item="{ element }">
43+
<h2>{{ element.id }} - {{ element.name }}</h2>
44+
</template>
45+
</DraggableList>
1146
</template>
1247

13-
<style scoped>
14-
.logo {
15-
height: 6em;
16-
padding: 1.5em;
17-
will-change: filter;
18-
}
19-
.logo:hover {
20-
filter: drop-shadow(0 0 2em #646cffaa);
21-
}
22-
.logo.vue:hover {
23-
filter: drop-shadow(0 0 2em #42b883aa);
24-
}
25-
</style>
48+
<style scoped></style>

src/components/DraggableList.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ const onDragOver = (itemIndex: number, event: DragEvent, push = false) => {
145145
const onDragEnd = () => {
146146
// Emits the end event to parent component, indicating that dragging has ended
147147
emit("end");
148-
};
149-
// Gets called when an element is dropped on another element
150-
const onDrop = () => {
148+
151149
// Emits the update event to parent component, indicating that the order is now done and ordering/moving is done
152150
if (!window.draggingItem) return;
153151
const { itemIndex, itemListUuid, initialItemIndex, initialItemListUuid } =
@@ -164,6 +162,9 @@ const onDrop = () => {
164162
delete window.draggingItem;
165163
};
166164
165+
// Gets called when an element is dropped on another element, currently not used
166+
const onDrop = () => {};
167+
167168
// Function that gets called for each item and returns attributes
168169
const convertAttributes = (item: any) =>
169170
Object.fromEntries(

0 commit comments

Comments
 (0)