1
0
mirror of synced 2024-11-25 06:16:08 +03:00

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
This commit is contained in:
Kevin Brown 2019-07-09 19:13:03 -04:00 committed by GitHub
parent 9491e1aae2
commit f9decd6094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 8 deletions

View File

@ -175,14 +175,8 @@ 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();
}
}
};
Search.prototype.handleSearch = function () {

View File

@ -255,3 +255,34 @@ test('removing a selected option changes the value', function (assert) {
syncDone();
});
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 = $(
'<select multiple="multiple">' +
' <option value="1">Text1</option>' +
' <option value="2">Text2</option>' +
'</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'});
});