Revert change to focusing behaviour in 4.0.6 (#5576)
This behaviour, where the focus was happening on a small asynchronous
delay, was added in commit 933189b92
late last year in a commit with
no supporting tickets or commit message explaining what the change
was trying to accomplish. This commit has effectly been reverted within
this commit, since it caused a regression in how focus was being
assigned that made it inconsistent with a standard `<select>`.
A test was added for this which ensures that we won't see that
regression again.
Fixes #5532
Fixes #5185
Closes #5552
This commit is contained in:
parent
d9260254c1
commit
1b5a962819
2
src/js/select2/selection/base.js
vendored
2
src/js/select2/selection/base.js
vendored
@ -81,9 +81,7 @@ define([
|
|||||||
self.$selection.removeAttr('aria-activedescendant');
|
self.$selection.removeAttr('aria-activedescendant');
|
||||||
self.$selection.removeAttr('aria-owns');
|
self.$selection.removeAttr('aria-owns');
|
||||||
|
|
||||||
window.setTimeout(function () {
|
|
||||||
self.$selection.trigger('focus');
|
self.$selection.trigger('focus');
|
||||||
}, 0);
|
|
||||||
|
|
||||||
self._detachCloseHandler(container);
|
self._detachCloseHandler(container);
|
||||||
});
|
});
|
||||||
|
41
tests/selection/focusing-tests.js
Normal file
41
tests/selection/focusing-tests.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
module('Selection containers - Managing focus');
|
||||||
|
|
||||||
|
var SingleSelection = require('select2/selection/single');
|
||||||
|
|
||||||
|
var $ = require('jquery');
|
||||||
|
var Options = require('select2/options');
|
||||||
|
|
||||||
|
var options = new Options({});
|
||||||
|
|
||||||
|
test('close sets the focus to the selection', function (assert) {
|
||||||
|
var $container = $('#qunit-fixture .event-container');
|
||||||
|
var container = new MockContainer();
|
||||||
|
var selection = new SingleSelection(
|
||||||
|
$('#qunit-fixture .single'),
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
|
var $selection = selection.render();
|
||||||
|
selection.bind(container, $container);
|
||||||
|
|
||||||
|
selection.update([{
|
||||||
|
id: 'test',
|
||||||
|
text: 'test'
|
||||||
|
}]);
|
||||||
|
|
||||||
|
$container.append($selection);
|
||||||
|
|
||||||
|
assert.notEqual(
|
||||||
|
document.activeElement,
|
||||||
|
$selection[0],
|
||||||
|
'The selection had focus originally'
|
||||||
|
);
|
||||||
|
|
||||||
|
container.trigger('close');
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
document.activeElement,
|
||||||
|
$selection[0],
|
||||||
|
'After close, focus must be set to selection'
|
||||||
|
);
|
||||||
|
});
|
@ -87,6 +87,7 @@
|
|||||||
|
|
||||||
<script src="selection/allowClear-tests.js" type="text/javascript"></script>
|
<script src="selection/allowClear-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/containerCss-tests.js" type="text/javascript"></script>
|
<script src="selection/containerCss-tests.js" type="text/javascript"></script>
|
||||||
|
<script src="selection/focusing-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/multiple-tests.js" type="text/javascript"></script>
|
<script src="selection/multiple-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/placeholder-tests.js" type="text/javascript"></script>
|
<script src="selection/placeholder-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/search-tests.js" type="text/javascript"></script>
|
<script src="selection/search-tests.js" type="text/javascript"></script>
|
||||||
|
@ -87,6 +87,7 @@
|
|||||||
|
|
||||||
<script src="selection/allowClear-tests.js" type="text/javascript"></script>
|
<script src="selection/allowClear-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/containerCss-tests.js" type="text/javascript"></script>
|
<script src="selection/containerCss-tests.js" type="text/javascript"></script>
|
||||||
|
<script src="selection/focusing-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/multiple-tests.js" type="text/javascript"></script>
|
<script src="selection/multiple-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/placeholder-tests.js" type="text/javascript"></script>
|
<script src="selection/placeholder-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/search-tests.js" type="text/javascript"></script>
|
<script src="selection/search-tests.js" type="text/javascript"></script>
|
||||||
|
@ -87,6 +87,7 @@
|
|||||||
|
|
||||||
<script src="selection/allowClear-tests.js" type="text/javascript"></script>
|
<script src="selection/allowClear-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/containerCss-tests.js" type="text/javascript"></script>
|
<script src="selection/containerCss-tests.js" type="text/javascript"></script>
|
||||||
|
<script src="selection/focusing-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/multiple-tests.js" type="text/javascript"></script>
|
<script src="selection/multiple-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/placeholder-tests.js" type="text/javascript"></script>
|
<script src="selection/placeholder-tests.js" type="text/javascript"></script>
|
||||||
<script src="selection/search-tests.js" type="text/javascript"></script>
|
<script src="selection/search-tests.js" type="text/javascript"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user