Skip to content

Commit f9decd6

Browse files
authored
Fix tag creation being broken in 4.0.7 (select2#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 select2#5485 Fixes select2#5516 Closes select2#5550
1 parent 9491e1a commit f9decd6

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

src/js/select2/selection/search.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,7 @@ define([
175175

176176
this.resizeSearch();
177177
if (searchHadFocus) {
178-
var isTagInput = this.$element.find('[data-select2-tag]').length;
179-
if (isTagInput) {
180-
// fix IE11 bug where tag input lost focus
181-
this.$element.focus();
182-
} else {
183-
this.$search.focus();
184-
}
178+
this.$search.focus();
185179
}
186180
};
187181

tests/integration/dom-changes.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,35 @@ test('removing a selected option changes the value', function (assert) {
254254
);
255255

256256
syncDone();
257-
});
257+
});
258+
259+
test('searching tags does not loose focus', function (assert) {
260+
assert.expect(1);
261+
262+
var asyncDone = assert.async();
263+
var $ = require('jquery');
264+
var Options = require('select2/options');
265+
var Select2 = require('select2/core');
266+
267+
var $select = $(
268+
'<select multiple="multiple">' +
269+
' <option value="1">Text1</option>' +
270+
' <option value="2">Text2</option>' +
271+
'</select>'
272+
);
273+
274+
$('#qunit-fixture').append($select);
275+
276+
var select = new Select2($select, {tags: true});
277+
278+
var inputEl = select.selection.$search[0];
279+
inputEl.focus();
280+
281+
select.on('selection:update', function() {
282+
assert.equal(document.activeElement, inputEl);
283+
asyncDone();
284+
});
285+
286+
select.selection.trigger('query', {term: 'f'});
287+
select.selection.trigger('query', {term: 'ff'});
288+
});

0 commit comments

Comments
 (0)