From f9decd60943f5b9d8d607a1f5351ba8caea97ccf Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Tue, 9 Jul 2019 19:13:03 -0400 Subject: [PATCH] Fix tag creation being broken in 4.0.7 (#5558) * Add test for losing focus when searching tag entries * Revert unknown unit test fix Removing this no longer breaks a unit test, and having it in here results in the select box receiving focus unexpectedly. It's not clear what problem this was solving, since it was manually applied from a series of pull requests. It claims to be fixing an issue that was specific to IE11, and I'm willing to re-introduce that bug because there doesn't appear to be a regression test for it, and it's breaking some critical use cases. The goal should be to focus the search box if it would have normally lost focus when the selection was updated. Fixes #5485 Fixes #5516 Closes #5550 --- src/js/select2/selection/search.js | 8 +------- tests/integration/dom-changes.js | 33 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 8 deletions(-) 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'}); +});