Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draggable: fix footer #6478

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading