2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-07 07:12:23 +03:00

fix: existing options should be selected with taggable (#1124)

Closes #1121
This commit is contained in:
Jeff Sagal
2020-03-20 09:31:59 -07:00
committed by GitHub
parent 8e061ce1af
commit f90a14470b
2 changed files with 21 additions and 6 deletions
+7 -5
View File
@@ -56,16 +56,18 @@ export default {
* Optionally clear the search input on selection.
* @return {void}
*/
typeAheadSelect () {
if (!this.taggable && this.filteredOptions[this.typeAheadPointer]) {
this.select(this.filteredOptions[this.typeAheadPointer]);
typeAheadSelect() {
const typeAheadOption = this.filteredOptions[this.typeAheadPointer];
if (typeAheadOption) {
this.select(typeAheadOption);
} else if (this.taggable && this.search.length) {
this.select(this.createOption(this.search));
}
if (this.clearSearchOnSelect) {
this.search = '';
this.search = "";
}
},
}
}
}
+14 -1
View File
@@ -1,4 +1,4 @@
import { searchSubmit, selectWithProps } from "../helpers";
import { mountDefault, searchSubmit, selectWithProps } from '../helpers';
import Select from '../../src/components/Select';
describe("When Tagging Is Enabled", () => {
@@ -243,4 +243,17 @@ describe("When Tagging Is Enabled", () => {
expect(Select.vm.selectedValue).toEqual([{ label: "one" }]);
expect(Select.vm.search).toEqual("");
});
it("will select an existing option on tab", async () => {
const Select = mountDefault({
taggable: true,
selectOnTab: true
});
Select.vm.typeAheadPointer = 0;
Select.find({ ref: "search" }).trigger("keydown.tab");
await Select.vm.$nextTick();
expect(Select.vm.selectedValue).toEqual(['one']);
})
});