Skip to content

Commit

Permalink
Fix Chinese input be interrupted problem
Browse files Browse the repository at this point in the history
For single search

select2#5252
Similar solution with michaelperrin/ajax-chosen#2 and facebook/react#3926
  • Loading branch information
lingceng committed May 16, 2018
1 parent 3b9a840 commit a3a339c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/js/select2/dropdown/search.js
Expand Up @@ -17,6 +17,7 @@ define([

this.$searchContainer = $search;
this.$search = $search.find('input');
this.isTyping = false;

$rendered.prepend($search);

Expand Down Expand Up @@ -46,6 +47,23 @@ define([
self.handleSearch(evt);
});

this.$search.on(
'compositionstart',
'.select2-search__field',
function (evt) {
self.isTyping = true;
}
);

this.$search.on(
'compositionend',
'.select2-search__field',
function (evt) {
self.isTyping = false;
self.handleSearch();
}
);

container.on('open', function () {
self.$search.attr('tabindex', 0);

Expand Down Expand Up @@ -83,6 +101,7 @@ define([
};

Search.prototype.handleSearch = function (evt) {
if (this.isTyping) { return; }
if (!this._keyUpPrevented) {
var input = this.$search.val();

Expand Down

0 comments on commit a3a339c

Please sign in to comment.