-
-
Notifications
You must be signed in to change notification settings - Fork 996
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
Drag and Drop functionality is added #1504
base: master
Are you sure you want to change the base?
Drag and Drop functionality is added #1504
Conversation
Everyone waited long for the drag and drop feature! 🚀 |
@mehdimohammadijan It's great that you worked on adding the drag'n'drop functionality! 🥇 I was trying to use your branch and I have the following feedback:
|
@mehdimohammadijan I would appreciate it if you also linked/published the code you used to make the screencast. Seeing what are the differences from how I use vue-multiselect would help me to figure out why it doesn't work (update the array value) for me. |
src/Multiselect.vue
Outdated
selectedOptions: { | ||
deep: true, | ||
handler: function (newVal) { | ||
this.$emit("addtag", newVal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why the emitted event should be addtag
, not the already used elsewhere input
event
this.$emit("addtag", newVal); | |
this.$emit("input", newVal); |
src/Multiselect.vue
Outdated
// the watch will look to any changes in value to adjust selectedOptions for adding and removing values | ||
immediate: true, | ||
handler(newVal, oldVal) { | ||
if (newVal && oldVal) { | ||
if (newVal.length > oldVal.length) { | ||
this.selectedOptions.push(newVal[newVal.length - 1]); | ||
} else { | ||
this.selectedOptions = this.selectedOptions.filter((option) => | ||
newVal.includes(option) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value
is coming from outside, so it can also be changed to a completely different array, not just adding and removing values. To handle any possible change of value
it should IMO look something like this:
// the watch will look to any changes in value to adjust selectedOptions for adding and removing values | |
immediate: true, | |
handler(newVal, oldVal) { | |
if (newVal && oldVal) { | |
if (newVal.length > oldVal.length) { | |
this.selectedOptions.push(newVal[newVal.length - 1]); | |
} else { | |
this.selectedOptions = this.selectedOptions.filter((option) => | |
newVal.includes(option) | |
); | |
} | |
} | |
// the watch will look to any changes in value to adjust selectedOptions | |
immediate: true, | |
handler(newVal) { | |
if (newVal && JSON.stringify(newVal) !== JSON.stringify(this.selectedOptions)) { | |
this.selectedOptions = [...newVal]; | |
} |
Hello, thank you for your review. |
Thank you for your reply @mehdimohammadijan
You cannot directly assign something to the value prop in multiselect component, but if you emit
Maybe it's not required. See https://github.com/shentao/vue-multiselect/pull/1504/files#r784726690.
Thanks that helps me a lot to understand how it was intended to be used. |
src/Multiselect.vue
Outdated
<draggable | ||
class="list-group" | ||
tag="ul" | ||
v-model="selectedOptions" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure about this, but maybe selectedOptions
wouldn't be needed if the v-model
was split to v-bind:value
and v-on:input
. Relevant docs: https://vuejs.org/v2/guide/components.html#Using-v-model-on-Components
v-model="selectedOptions" | |
v-bind:value="value" | |
v-on:input="(v) => $emit('input', v)" |
… and additional array is removed.
I used value prop in v-model directly for draggablility, and additional array selectedOptions is removed. Now it is more clean. |
I have added Drag and Drop functioanlity by incorporating Vue Draggable library (https://github.com/SortableJS/Vue.Draggable).
screen cast: https://watch.screencastify.com/v/sxxf2JcWVYR52ZvG8EHO