2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-05-17 02:29:37 +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 return a unique key for each option.\n` +
'https://vue-select.org/api/props.html#getoptionkey'
)
return null
);
}
}
}
@@ -402,14 +401,9 @@
*/
createOption: {
type: Function,
default(newOption) {
if (typeof this.optionList[0] === 'object') {
newOption = {[this.label]: newOption}
}
this.$emit('option:created', newOption)
return newOption
}
default (option) {
return (typeof this.optionList[0] === 'object') ? {[this.label]: option} : option;
},
},
/**
@@ -581,7 +575,8 @@
select(option) {
if (!this.isOptionSelected(option)) {
if (this.taggable && !this.optionExists(option)) {
option = this.createOption(option)
option = this.createOption(option);
this.$emit('option:created', option);
}
if (this.multiple) {
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"]);
});
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", () => {
const Select = selectWithProps({
filterable: false,