mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-22 10:30:34 +03:00
fix(reduce): do not set $data._value in updateValue if reduce option is set
Closes #1210
This commit is contained in:
@@ -713,7 +713,7 @@
|
|||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
updateValue (value) {
|
updateValue (value) {
|
||||||
if (this.isTrackingValues) {
|
if (typeof this.value === 'undefined') {
|
||||||
// Vue select has to manage value
|
// Vue select has to manage value
|
||||||
this.$data._value = value;
|
this.$data._value = value;
|
||||||
}
|
}
|
||||||
@@ -989,7 +989,6 @@
|
|||||||
*/
|
*/
|
||||||
selectedValue () {
|
selectedValue () {
|
||||||
let value = this.value;
|
let value = this.value;
|
||||||
|
|
||||||
if (this.isTrackingValues) {
|
if (this.isTrackingValues) {
|
||||||
// Vue select has to manage value internally
|
// Vue select has to manage value internally
|
||||||
value = this.$data._value;
|
value = this.$data._value;
|
||||||
|
|||||||
@@ -100,19 +100,36 @@ describe("When reduce prop is defined", () => {
|
|||||||
expect(Select.vm.selectedValue).toEqual([]);
|
expect(Select.vm.selectedValue).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can use v-model syntax for a two way binding to a parent component", () => {
|
it("can use v-model syntax for a two way binding to a parent component", async () => {
|
||||||
const Parent = mount({
|
const Parent = mount({
|
||||||
data: () => ({
|
data: () => ({
|
||||||
reduce: option => option.value,
|
reduce: option => option.value,
|
||||||
value: "foo",
|
current: "foo",
|
||||||
options: [
|
options: [
|
||||||
{ label: "This is Foo", value: "foo" },
|
{ label: "This is Foo", value: "foo" },
|
||||||
{ label: "This is Bar", value: "bar" },
|
{ label: "This is Bar", value: "bar" },
|
||||||
{ label: "This is Baz", value: "baz" }
|
{ label: "This is Baz", value: "baz" }
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
template: `<div><v-select :reduce="option => option.value" :options="options" v-model="value"></v-select></div>`,
|
components: { "v-select": VueSelect },
|
||||||
components: { "v-select": VueSelect }
|
computed: {
|
||||||
|
value: {
|
||||||
|
get() {
|
||||||
|
return this.current;
|
||||||
|
},
|
||||||
|
set(value) {
|
||||||
|
if (value == 'baz') return;
|
||||||
|
this.current = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<v-select
|
||||||
|
v-model="value"
|
||||||
|
:reduce="option => option.value"
|
||||||
|
:options="options"
|
||||||
|
/>
|
||||||
|
`
|
||||||
});
|
});
|
||||||
const Select = Parent.vm.$children[0];
|
const Select = Parent.vm.$children[0];
|
||||||
|
|
||||||
@@ -120,7 +137,15 @@ describe("When reduce prop is defined", () => {
|
|||||||
expect(Select.selectedValue).toEqual([{ label: "This is Foo", value: "foo" }]);
|
expect(Select.selectedValue).toEqual([{ label: "This is Foo", value: "foo" }]);
|
||||||
|
|
||||||
Select.select({ label: "This is Bar", value: "bar" });
|
Select.select({ label: "This is Bar", value: "bar" });
|
||||||
|
await Select.$nextTick();
|
||||||
expect(Parent.vm.value).toEqual("bar");
|
expect(Parent.vm.value).toEqual("bar");
|
||||||
|
expect(Select.selectedValue).toEqual([{ label: "This is Bar", value: "bar" }]);
|
||||||
|
|
||||||
|
// Parent denies to set baz
|
||||||
|
Select.select({ label: "This is Baz", value: "baz" });
|
||||||
|
await Select.$nextTick();
|
||||||
|
expect(Select.selectedValue).toEqual([{ label: "This is Bar", value: "bar" }]);
|
||||||
|
expect(Parent.vm.value).toEqual('bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can generate labels using a custom label key", () => {
|
it("can generate labels using a custom label key", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user