2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-22 10:30:34 +03:00

pull $emit out of create-option function

This commit is contained in:
Jeff
2019-11-09 14:19:19 -08:00
parent fd218db450
commit cde2316e4f
2 changed files with 20 additions and 11 deletions
+6 -11
View File
@@ -296,8 +296,7 @@
`to generate unique key. Please provide'getOptionKey' prop ` + `to generate unique key. Please provide'getOptionKey' prop ` +
`to return a unique key for each option.\n` + `to return a unique key for each option.\n` +
'https://vue-select.org/api/props.html#getoptionkey' 'https://vue-select.org/api/props.html#getoptionkey'
) );
return null
} }
} }
} }
@@ -402,14 +401,9 @@
*/ */
createOption: { createOption: {
type: Function, type: Function,
default(newOption) { default (option) {
if (typeof this.optionList[0] === 'object') { return (typeof this.optionList[0] === 'object') ? {[this.label]: option} : option;
newOption = {[this.label]: newOption} },
}
this.$emit('option:created', newOption)
return newOption
}
}, },
/** /**
@@ -581,7 +575,8 @@
select(option) { select(option) {
if (!this.isOptionSelected(option)) { if (!this.isOptionSelected(option)) {
if (this.taggable && !this.optionExists(option)) { if (this.taggable && !this.optionExists(option)) {
option = this.createOption(option) option = this.createOption(option);
this.$emit('option:created', option);
} }
if (this.multiple) { if (this.multiple) {
option = this.selectedValue.concat(option) option = this.selectedValue.concat(option)
+14
View File
@@ -80,6 +80,20 @@ describe("When Tagging Is Enabled", () => {
expect(Select.vm.optionList).toEqual(["one", "two", "three"]); expect(Select.vm.optionList).toEqual(["one", "two", "three"]);
}); });
it("should pushTags even if the consumer has defined a createOption callback", () => {
const Select = selectWithProps({
pushTags: true,
taggable: true,
createOption: option => option,
options: ["one", "two"]
});
searchSubmit(Select, "three");
expect(Select.vm.pushedTags).toEqual(["three"]);
expect(Select.vm.optionList).toEqual(["one", "two", "three"]);
});
it("should add a freshly created option/tag to the options list when pushTags is true and filterable is false", () => { it("should add a freshly created option/tag to the options list when pushTags is true and filterable is false", () => {
const Select = selectWithProps({ const Select = selectWithProps({
filterable: false, filterable: false,