Skip to content

Commit

Permalink
Fix tag creation being broken in 4.0.7 (#5558)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kevin-brown committed Jul 9, 2019
1 parent 9491e1a commit f9decd6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
8 changes: 1 addition & 7 deletions src/js/select2/selection/search.js
Expand Up @@ -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();
}
};

Expand Down
33 changes: 32 additions & 1 deletion tests/integration/dom-changes.js
Expand Up @@ -254,4 +254,35 @@ 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'});
});

0 comments on commit f9decd6

Please sign in to comment.