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:
parent
9491e1aae2
commit
f9decd6094
8
src/js/select2/selection/search.js
vendored
8
src/js/select2/selection/search.js
vendored
@ -175,13 +175,7 @@ define([
|
|||||||
|
|
||||||
this.resizeSearch();
|
this.resizeSearch();
|
||||||
if (searchHadFocus) {
|
if (searchHadFocus) {
|
||||||
var isTagInput = this.$element.find('[data-select2-tag]').length;
|
this.$search.focus();
|
||||||
if (isTagInput) {
|
|
||||||
// fix IE11 bug where tag input lost focus
|
|
||||||
this.$element.focus();
|
|
||||||
} else {
|
|
||||||
this.$search.focus();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -255,3 +255,34 @@ test('removing a selected option changes the value', function (assert) {
|
|||||||
|
|
||||||
syncDone();
|
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'});
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user