diff --git a/src/js/select2/selection/search.js b/src/js/select2/selection/search.js index 3ff96f94db..9ce321beae 100644 --- a/src/js/select2/selection/search.js +++ b/src/js/select2/selection/search.js @@ -175,13 +175,7 @@ define([ this.resizeSearch(); if (searchHadFocus) { - var isTagInput = this.$element.find('[data-select2-tag]').length; - if (isTagInput) { - // fix IE11 bug where tag input lost focus - this.$element.focus(); - } else { - this.$search.focus(); - } + this.$search.focus(); } }; diff --git a/tests/integration/dom-changes.js b/tests/integration/dom-changes.js index 2d89ae2acf..65f3fb9129 100644 --- a/tests/integration/dom-changes.js +++ b/tests/integration/dom-changes.js @@ -254,4 +254,35 @@ test('removing a selected option changes the value', function (assert) { ); syncDone(); -}); \ No newline at end of file +}); + +test('searching tags does not loose focus', function (assert) { + assert.expect(1); + + var asyncDone = assert.async(); + var $ = require('jquery'); + var Options = require('select2/options'); + var Select2 = require('select2/core'); + + var $select = $( + '' + ); + + $('#qunit-fixture').append($select); + + var select = new Select2($select, {tags: true}); + + var inputEl = select.selection.$search[0]; + inputEl.focus(); + + select.on('selection:update', function() { + assert.equal(document.activeElement, inputEl); + asyncDone(); + }); + + select.selection.trigger('query', {term: 'f'}); + select.selection.trigger('query', {term: 'ff'}); +});