Improved focus detection and key handling
Now the focus of the selection container is correctly monitored so there is a consistent 1px black border on the default theme whenever it is focused. This requires `focusin`/`focusout` support, which is supported by all major browsers except for Firefox. In Firefox, the old focus appearance is still consistent and has not been broken by this update. The key handling has also been improved such that some of the logic detection that was previously done within the search handlers for multiple select searches is now pushed back to the base selection. This closes https://github.com/select2/select2/issues/2995.
This commit is contained in:
parent
b382fdca9c
commit
3d013020ae
3
dist/css/select2.css
vendored
3
dist/css/select2.css
vendored
@ -200,6 +200,9 @@
|
||||
.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
|
||||
margin-left: 2px;
|
||||
margin-right: auto; }
|
||||
.select2-container--default.select2-container--focus .select2-selection--multiple {
|
||||
border: solid black 1px;
|
||||
outline: 0; }
|
||||
.select2-container--default.select2-container--disabled .select2-selection--multiple {
|
||||
background-color: #eee;
|
||||
cursor: default; }
|
||||
|
2
dist/css/select2.min.css
vendored
2
dist/css/select2.min.css
vendored
File diff suppressed because one or more lines are too long
37
dist/js/select2.amd.full.js
vendored
37
dist/js/select2.amd.full.js
vendored
@ -792,8 +792,13 @@ define('select2/selection/base',[
|
||||
'</span>'
|
||||
);
|
||||
|
||||
this._tabindex = this.$element.data('old-tabindex') ||
|
||||
this.$element.attr('tabindex') || 0;
|
||||
this._tabindex = 0;
|
||||
|
||||
if (this.$element.data('old-tabindex') != null) {
|
||||
this._tabindex = this.$element.data('old-tabindex');
|
||||
} else if (this.$element.attr('tabindex') != null) {
|
||||
this._tabindex = this.$element.attr('tabindex');
|
||||
}
|
||||
|
||||
$selection.attr('title', this.$element.attr('title'));
|
||||
$selection.attr('tabindex', this._tabindex);
|
||||
@ -813,6 +818,14 @@ define('select2/selection/base',[
|
||||
|
||||
this.$selection.attr('aria-owns', resultsId);
|
||||
|
||||
this.$selection.on('focus', function (evt) {
|
||||
self.trigger('focus', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('blur', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('keydown', function (evt) {
|
||||
self.trigger('keypress', evt);
|
||||
|
||||
@ -1267,13 +1280,17 @@ define('select2/selection/search',[
|
||||
self.$search.prop('disabled', true);
|
||||
});
|
||||
|
||||
this.$selection.on('focusin', '.select2-search--inline', function (evt) {
|
||||
self.trigger('focus', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('focusout', '.select2-search--inline', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
});
|
||||
|
||||
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();
|
||||
@ -4394,6 +4411,14 @@ define('select2/core',[
|
||||
self.$container.addClass('select2-container--disabled');
|
||||
});
|
||||
|
||||
this.on('focus', function () {
|
||||
self.$container.addClass('select2-container--focus');
|
||||
});
|
||||
|
||||
this.on('blur', function () {
|
||||
self.$container.removeClass('select2-container--focus');
|
||||
});
|
||||
|
||||
this.on('query', function (params) {
|
||||
this.data.query(params, function (data) {
|
||||
self.trigger('results:all', {
|
||||
|
37
dist/js/select2.amd.js
vendored
37
dist/js/select2.amd.js
vendored
@ -792,8 +792,13 @@ define('select2/selection/base',[
|
||||
'</span>'
|
||||
);
|
||||
|
||||
this._tabindex = this.$element.data('old-tabindex') ||
|
||||
this.$element.attr('tabindex') || 0;
|
||||
this._tabindex = 0;
|
||||
|
||||
if (this.$element.data('old-tabindex') != null) {
|
||||
this._tabindex = this.$element.data('old-tabindex');
|
||||
} else if (this.$element.attr('tabindex') != null) {
|
||||
this._tabindex = this.$element.attr('tabindex');
|
||||
}
|
||||
|
||||
$selection.attr('title', this.$element.attr('title'));
|
||||
$selection.attr('tabindex', this._tabindex);
|
||||
@ -813,6 +818,14 @@ define('select2/selection/base',[
|
||||
|
||||
this.$selection.attr('aria-owns', resultsId);
|
||||
|
||||
this.$selection.on('focus', function (evt) {
|
||||
self.trigger('focus', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('blur', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('keydown', function (evt) {
|
||||
self.trigger('keypress', evt);
|
||||
|
||||
@ -1267,13 +1280,17 @@ define('select2/selection/search',[
|
||||
self.$search.prop('disabled', true);
|
||||
});
|
||||
|
||||
this.$selection.on('focusin', '.select2-search--inline', function (evt) {
|
||||
self.trigger('focus', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('focusout', '.select2-search--inline', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
});
|
||||
|
||||
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();
|
||||
@ -4394,6 +4411,14 @@ define('select2/core',[
|
||||
self.$container.addClass('select2-container--disabled');
|
||||
});
|
||||
|
||||
this.on('focus', function () {
|
||||
self.$container.addClass('select2-container--focus');
|
||||
});
|
||||
|
||||
this.on('blur', function () {
|
||||
self.$container.removeClass('select2-container--focus');
|
||||
});
|
||||
|
||||
this.on('query', function (params) {
|
||||
this.data.query(params, function (data) {
|
||||
self.trigger('results:all', {
|
||||
|
37
dist/js/select2.full.js
vendored
37
dist/js/select2.full.js
vendored
@ -1231,8 +1231,13 @@ define('select2/selection/base',[
|
||||
'</span>'
|
||||
);
|
||||
|
||||
this._tabindex = this.$element.data('old-tabindex') ||
|
||||
this.$element.attr('tabindex') || 0;
|
||||
this._tabindex = 0;
|
||||
|
||||
if (this.$element.data('old-tabindex') != null) {
|
||||
this._tabindex = this.$element.data('old-tabindex');
|
||||
} else if (this.$element.attr('tabindex') != null) {
|
||||
this._tabindex = this.$element.attr('tabindex');
|
||||
}
|
||||
|
||||
$selection.attr('title', this.$element.attr('title'));
|
||||
$selection.attr('tabindex', this._tabindex);
|
||||
@ -1252,6 +1257,14 @@ define('select2/selection/base',[
|
||||
|
||||
this.$selection.attr('aria-owns', resultsId);
|
||||
|
||||
this.$selection.on('focus', function (evt) {
|
||||
self.trigger('focus', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('blur', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('keydown', function (evt) {
|
||||
self.trigger('keypress', evt);
|
||||
|
||||
@ -1706,13 +1719,17 @@ define('select2/selection/search',[
|
||||
self.$search.prop('disabled', true);
|
||||
});
|
||||
|
||||
this.$selection.on('focusin', '.select2-search--inline', function (evt) {
|
||||
self.trigger('focus', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('focusout', '.select2-search--inline', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
});
|
||||
|
||||
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();
|
||||
@ -4833,6 +4850,14 @@ define('select2/core',[
|
||||
self.$container.addClass('select2-container--disabled');
|
||||
});
|
||||
|
||||
this.on('focus', function () {
|
||||
self.$container.addClass('select2-container--focus');
|
||||
});
|
||||
|
||||
this.on('blur', function () {
|
||||
self.$container.removeClass('select2-container--focus');
|
||||
});
|
||||
|
||||
this.on('query', function (params) {
|
||||
this.data.query(params, function (data) {
|
||||
self.trigger('results:all', {
|
||||
|
4
dist/js/select2.full.min.js
vendored
4
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
37
dist/js/select2.js
vendored
37
dist/js/select2.js
vendored
@ -1231,8 +1231,13 @@ define('select2/selection/base',[
|
||||
'</span>'
|
||||
);
|
||||
|
||||
this._tabindex = this.$element.data('old-tabindex') ||
|
||||
this.$element.attr('tabindex') || 0;
|
||||
this._tabindex = 0;
|
||||
|
||||
if (this.$element.data('old-tabindex') != null) {
|
||||
this._tabindex = this.$element.data('old-tabindex');
|
||||
} else if (this.$element.attr('tabindex') != null) {
|
||||
this._tabindex = this.$element.attr('tabindex');
|
||||
}
|
||||
|
||||
$selection.attr('title', this.$element.attr('title'));
|
||||
$selection.attr('tabindex', this._tabindex);
|
||||
@ -1252,6 +1257,14 @@ define('select2/selection/base',[
|
||||
|
||||
this.$selection.attr('aria-owns', resultsId);
|
||||
|
||||
this.$selection.on('focus', function (evt) {
|
||||
self.trigger('focus', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('blur', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('keydown', function (evt) {
|
||||
self.trigger('keypress', evt);
|
||||
|
||||
@ -1706,13 +1719,17 @@ define('select2/selection/search',[
|
||||
self.$search.prop('disabled', true);
|
||||
});
|
||||
|
||||
this.$selection.on('focusin', '.select2-search--inline', function (evt) {
|
||||
self.trigger('focus', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('focusout', '.select2-search--inline', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
});
|
||||
|
||||
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();
|
||||
@ -4833,6 +4850,14 @@ define('select2/core',[
|
||||
self.$container.addClass('select2-container--disabled');
|
||||
});
|
||||
|
||||
this.on('focus', function () {
|
||||
self.$container.addClass('select2-container--focus');
|
||||
});
|
||||
|
||||
this.on('blur', function () {
|
||||
self.$container.removeClass('select2-container--focus');
|
||||
});
|
||||
|
||||
this.on('query', function (params) {
|
||||
this.data.query(params, function (data) {
|
||||
self.trigger('results:all', {
|
||||
|
4
dist/js/select2.min.js
vendored
4
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
8
src/js/select2/core.js
vendored
8
src/js/select2/core.js
vendored
@ -263,6 +263,14 @@ define([
|
||||
self.$container.addClass('select2-container--disabled');
|
||||
});
|
||||
|
||||
this.on('focus', function () {
|
||||
self.$container.addClass('select2-container--focus');
|
||||
});
|
||||
|
||||
this.on('blur', function () {
|
||||
self.$container.removeClass('select2-container--focus');
|
||||
});
|
||||
|
||||
this.on('query', function (params) {
|
||||
this.data.query(params, function (data) {
|
||||
self.trigger('results:all', {
|
||||
|
17
src/js/select2/selection/base.js
vendored
17
src/js/select2/selection/base.js
vendored
@ -19,8 +19,13 @@ define([
|
||||
'</span>'
|
||||
);
|
||||
|
||||
this._tabindex = this.$element.data('old-tabindex') ||
|
||||
this.$element.attr('tabindex') || 0;
|
||||
this._tabindex = 0;
|
||||
|
||||
if (this.$element.data('old-tabindex') != null) {
|
||||
this._tabindex = this.$element.data('old-tabindex');
|
||||
} else if (this.$element.attr('tabindex') != null) {
|
||||
this._tabindex = this.$element.attr('tabindex');
|
||||
}
|
||||
|
||||
$selection.attr('title', this.$element.attr('title'));
|
||||
$selection.attr('tabindex', this._tabindex);
|
||||
@ -40,6 +45,14 @@ define([
|
||||
|
||||
this.$selection.attr('aria-owns', resultsId);
|
||||
|
||||
this.$selection.on('focus', function (evt) {
|
||||
self.trigger('focus', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('blur', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('keydown', function (evt) {
|
||||
self.trigger('keypress', evt);
|
||||
|
||||
|
12
src/js/select2/selection/search.js
vendored
12
src/js/select2/selection/search.js
vendored
@ -50,13 +50,17 @@ define([
|
||||
self.$search.prop('disabled', true);
|
||||
});
|
||||
|
||||
this.$selection.on('focusin', '.select2-search--inline', function (evt) {
|
||||
self.trigger('focus', evt);
|
||||
});
|
||||
|
||||
this.$selection.on('focusout', '.select2-search--inline', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
});
|
||||
|
||||
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();
|
||||
|
@ -75,14 +75,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
&.select2-container--focus {
|
||||
.select2-selection--multiple {
|
||||
border: solid black 1px;
|
||||
outline: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.select2-container--disabled {
|
||||
.select2-selection--multiple {
|
||||
background-color: #eee;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.select2-selection__choice__remove {
|
||||
display: none;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user