mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-19 09:50:33 +03:00
support null values with reduce
This commit is contained in:
@@ -508,7 +508,7 @@
|
|||||||
created() {
|
created() {
|
||||||
this.mutableLoading = this.loading;
|
this.mutableLoading = this.loading;
|
||||||
|
|
||||||
if (this.value !== null && this.isTrackingValues) {
|
if (typeof this.value !== "undefined" && this.isTrackingValues) {
|
||||||
this.setInternalValueFromOptions(this.value)
|
this.setInternalValueFromOptions(this.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,6 +166,20 @@ describe("When reduce prop is defined", () => {
|
|||||||
expect(Select.vm.selectedValue).toEqual([option]);
|
expect(Select.vm.selectedValue).toEqual([option]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('works with null values', () => {
|
||||||
|
const option = {value: null, label: 'No'};
|
||||||
|
const Select = shallowMount(VueSelect, {
|
||||||
|
propsData: {
|
||||||
|
reduce: option => option.value,
|
||||||
|
options: [option, {value: 1, label: 'Yes'}],
|
||||||
|
value: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(Select.vm.findOptionFromReducedValue(option)).toEqual(option);
|
||||||
|
expect(Select.vm.selectedValue).toEqual([option]);
|
||||||
|
});
|
||||||
|
|
||||||
describe("And when a reduced option is a nested object", () => {
|
describe("And when a reduced option is a nested object", () => {
|
||||||
it("can determine if an object is pre-selected", () => {
|
it("can determine if an object is pre-selected", () => {
|
||||||
const nestedOption = { value: { nested: true }, label: "foo" };
|
const nestedOption = { value: { nested: true }, label: "foo" };
|
||||||
|
|||||||
Reference in New Issue
Block a user