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

add support for composing #900

This commit is contained in:
Jeff
2019-11-07 15:45:12 -08:00
parent bc5d0d9e4a
commit 8cce5e0ea2
2 changed files with 41 additions and 5 deletions
+11 -5
View File
@@ -79,6 +79,9 @@
import ajax from '../mixins/ajax' import ajax from '../mixins/ajax'
import childComponents from './childComponents'; import childComponents from './childComponents';
/**
* @name VueSelect
*/
export default { export default {
components: {...childComponents}, components: {...childComponents},
@@ -302,12 +305,12 @@
/** /**
* Select the current value if selectOnTab is enabled * Select the current value if selectOnTab is enabled
* @deprecated * @deprecated since 3.3
*/ */
onTab: { onTab: {
type: Function, type: Function,
default: function () { default: function () {
if (this.selectOnTab) { if (this.selectOnTab && !this.isComposing) {
this.typeAheadSelect(); this.typeAheadSelect();
} }
}, },
@@ -450,7 +453,7 @@
/** /**
* When true, hitting the 'tab' key will select the current select value * When true, hitting the 'tab' key will select the current select value
* @type {Boolean} * @type {Boolean}
* @deprecated * @deprecated since 3.3 - use selectOnKeyCodes instead
*/ */
selectOnTab: { selectOnTab: {
type: Boolean, type: Boolean,
@@ -500,6 +503,7 @@
return { return {
search: '', search: '',
open: false, open: false,
isComposing: false,
pushedTags: [], pushedTags: [],
_value: [] // Internal value managed by Vue Select if no `value` prop is passed _value: [] // Internal value managed by Vue Select if no `value` prop is passed
} }
@@ -873,7 +877,7 @@
onSearchKeyDown (e) { onSearchKeyDown (e) {
const preventAndSelect = e => { const preventAndSelect = e => {
e.preventDefault(); e.preventDefault();
return this.typeAheadSelect(); return !this.isComposing && this.typeAheadSelect();
}; };
const defaults = { const defaults = {
@@ -977,10 +981,12 @@
'value': this.search, 'value': this.search,
}, },
events: { events: {
'compositionstart': () => this.isComposing = true,
'compositionend': () => this.isComposing = false,
'keydown': this.onSearchKeyDown, 'keydown': this.onSearchKeyDown,
'blur': this.onSearchBlur, 'blur': this.onSearchBlur,
'focus': this.onSearchFocus, 'focus': this.onSearchFocus,
'input': (e) => this.search = e.target.value 'input': (e) => this.search = e.target.value,
}, },
}, },
spinner: { spinner: {
+30
View File
@@ -41,4 +41,34 @@ describe('Custom Keydown Handlers', () => {
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
describe('CompositionEvent support', () => {
it('will not select a value with enter if the user is composing', () => {
const Select = mountDefault();
const spy = jest.spyOn(Select.vm, 'typeAheadSelect');
Select.find({ref: 'search'}).trigger('compositionstart');
Select.find({ref: 'search'}).trigger('keydown.enter');
expect(spy).toHaveBeenCalledTimes(0);
Select.find({ref: 'search'}).trigger('compositionend');
Select.find({ref: 'search'}).trigger('keydown.enter');
expect(spy).toHaveBeenCalledTimes(1);
});
it('will not select a value with tab if the user is composing', () => {
const Select = mountDefault({selectOnTab: true});
const spy = jest.spyOn(Select.vm, 'typeAheadSelect');
Select.find({ref: 'search'}).trigger('compositionstart');
Select.find({ref: 'search'}).trigger('keydown.tab');
expect(spy).toHaveBeenCalledTimes(0);
Select.find({ref: 'search'}).trigger('compositionend');
Select.find({ref: 'search'}).trigger('keydown.tab');
expect(spy).toHaveBeenCalledTimes(1);
});
});
}); });