Skip to content

Commit

Permalink
Draggable: fix footer
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Jun 9, 2024
1 parent 00355cd commit 83ccdd2
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions panel/src/components/Misc/Draggable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<!-- @slot Items to be sortable via drag and drop -->
<slot />

<footer v-if="$slots.footer" ref="footer" class="k-draggable-footer">
<template v-if="$slots.footer">
<!-- @slot Non-sortable footer -->
<slot name="footer" />
</footer>
</template>
</component>
</template>

Expand Down Expand Up @@ -102,6 +102,7 @@ export default {
}
},
mounted() {
this.disableFooter();
this.create();
},
methods: {
Expand Down Expand Up @@ -159,10 +160,10 @@ export default {
},
// Event when you move an item in the list or between lists
onMove: (event, originalEvent) => {
onMove: (event) => {
// ensure footer stays non-sortable at the bottom
if (originalEvent.target === this.$refs.footer) {
return -1;
if (event.dragged.classList.contains("k-draggable-footer")) {
return false;
}
if (this.move) {
Expand All @@ -184,6 +185,21 @@ export default {
}
});
},
disableFooter() {
if (this.$slots.footer) {
// get as many nodes from the back of the list
// as footer elements are present
const nodes = [...this.$el.childNodes].slice(
-1 * this.$slots.footer.length
);
// add class to any node in the footer slot
// to allow filtering it as non-draggable
for (const node of nodes) {
node.classList?.add("k-draggable-footer");
}
}
},
getInstance(element) {
// get the Vue instance from HTMLElement
element = element.__vue__;
Expand Down

0 comments on commit 83ccdd2

Please sign in to comment.