1
0
mirror of synced 2024-11-25 22:36:03 +03:00

Autofocus search field in multiple select

In a single select, the search field is automatically focused when
the select is opened. This also applied to multiple selects, but
this was causing issues because the container was automatically
focused when the dropdown was closed.

This makes a change such that the search field is automatically
focused when the dropdown is closed.

This closes https://github.com/select2/select2/issues/2995.
This commit is contained in:
Kevin Brown 2015-02-09 15:43:46 -05:00
parent 4dda5e7a74
commit 0c0e2527fa
7 changed files with 29 additions and 4 deletions

View File

@ -1256,6 +1256,7 @@ define('select2/selection/search',[
self.$search.attr('tabindex', -1);
self.$search.val('');
self.$search.focus();
});
container.on('enable', function () {
@ -1269,6 +1270,10 @@ define('select2/selection/search',[
this.$selection.on('keydown', '.select2-search--inline', function (evt) {
evt.stopPropagation();
if (!container.isOpen()) {
self.trigger('open');
}
self.trigger('keypress', evt);
self._keyUpPrevented = evt.isDefaultPrevented();

View File

@ -1256,6 +1256,7 @@ define('select2/selection/search',[
self.$search.attr('tabindex', -1);
self.$search.val('');
self.$search.focus();
});
container.on('enable', function () {
@ -1269,6 +1270,10 @@ define('select2/selection/search',[
this.$selection.on('keydown', '.select2-search--inline', function (evt) {
evt.stopPropagation();
if (!container.isOpen()) {
self.trigger('open');
}
self.trigger('keypress', evt);
self._keyUpPrevented = evt.isDefaultPrevented();

View File

@ -1694,6 +1694,7 @@ define('select2/selection/search',[
self.$search.attr('tabindex', -1);
self.$search.val('');
self.$search.focus();
});
container.on('enable', function () {
@ -1707,6 +1708,10 @@ define('select2/selection/search',[
this.$selection.on('keydown', '.select2-search--inline', function (evt) {
evt.stopPropagation();
if (!container.isOpen()) {
self.trigger('open');
}
self.trigger('keypress', evt);
self._keyUpPrevented = evt.isDefaultPrevented();

File diff suppressed because one or more lines are too long

5
dist/js/select2.js vendored
View File

@ -1694,6 +1694,7 @@ define('select2/selection/search',[
self.$search.attr('tabindex', -1);
self.$search.val('');
self.$search.focus();
});
container.on('enable', function () {
@ -1707,6 +1708,10 @@ define('select2/selection/search',[
this.$selection.on('keydown', '.select2-search--inline', function (evt) {
evt.stopPropagation();
if (!container.isOpen()) {
self.trigger('open');
}
self.trigger('keypress', evt);
self._keyUpPrevented = evt.isDefaultPrevented();

File diff suppressed because one or more lines are too long

View File

@ -39,6 +39,7 @@ define([
self.$search.attr('tabindex', -1);
self.$search.val('');
self.$search.focus();
});
container.on('enable', function () {
@ -52,6 +53,10 @@ define([
this.$selection.on('keydown', '.select2-search--inline', function (evt) {
evt.stopPropagation();
if (!container.isOpen()) {
self.trigger('open');
}
self.trigger('keypress', evt);
self._keyUpPrevented = evt.isDefaultPrevented();