Skip to content

Commit

Permalink
Merge pull request #2335 from the-events-calendar/fix/FBAR-330-tabind…
Browse files Browse the repository at this point in the history
…ex-search

Fix/fbar 330 tabindex search
  • Loading branch information
Camwyn authored Dec 31, 2024
2 parents 4d3f741 + 9d66e46 commit 3b6d19f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-FBAR-330-tabindex-search
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Improves accessibility of select2 component, allowing tabbing into elements.
43 changes: 23 additions & 20 deletions vendor/tribe-selectWoo/dist/js/selectWoo.full.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ S2.define('select2/results',[

Results.prototype.render = function () {
var $results = $(
'<ul class="select2-results__options" role="listbox" tabindex="-1"></ul>'
'<ul class="select2-results__options" role="listbox"></ul>'
);

if (this.options.get('multiple')) {
Expand Down Expand Up @@ -958,7 +958,7 @@ S2.define('select2/results',[
var attrs = {
'role': 'option',
'data-selected': 'false',
'tabindex': -1
'tabindex':'0',
};

if (data.disabled) {
Expand Down Expand Up @@ -988,10 +988,17 @@ S2.define('select2/results',[

option.setAttribute(attr, val);
}
var $option = $(option);

if (data.children) {
var $option = $(option);
$option.on( 'blur', function() {
$option.attr( 'data-selected', 'false' );
});

$option.on( 'focus', function() {
$option.attr( 'data-selected', 'true' );
});

if (data.children) {
var label = document.createElement('strong');
label.className = 'select2-results__group';

Expand Down Expand Up @@ -1040,7 +1047,6 @@ S2.define('select2/results',[

if (container.isOpen()) {
self.setClasses();
self.highlightFirstItem();
}
});

Expand Down Expand Up @@ -1875,7 +1881,7 @@ S2.define('select2/selection/allowClear',[
}
}

// Allow clearing when the data-placeholder attribute isn't set.
// Allow clearing when the data-placeholder attribute isn't set.
if ( typeof this.placeholder !== 'undefined' ) {
this.$element.val( this.placeholder.id ).trigger( 'change' );
} else {
Expand Down Expand Up @@ -1928,7 +1934,7 @@ S2.define('select2/selection/search',[
Search.prototype.render = function (decorated) {
var $search = $(
'<li class="select2-search select2-search--inline">' +
'<input class="select2-search__field" type="text" tabindex="-1"' +
'<input class="select2-search__field" type="text"' +
' autocomplete="off" autocorrect="off" autocapitalize="none"' +
' spellcheck="false" role="textbox" aria-autocomplete="list" />' +
'</li>'
Expand Down Expand Up @@ -2079,7 +2085,6 @@ S2.define('select2/selection/search',[
* @private
*/
Search.prototype._transferTabIndex = function (decorated) {
this.$search.attr('tabindex', this.$selection.attr('tabindex'));
this.$selection.attr('tabindex', '-1');
};

Expand Down Expand Up @@ -3697,9 +3702,9 @@ S2.define('select2/data/tags',[
};

Tags.prototype.createTag = function (decorated, params) {
if ( 'string' !== typeof params.term ) {
return null;
}
if ( 'string' !== typeof params.term ) {
return null;
}

var term = params.term.trim();

Expand Down Expand Up @@ -3991,16 +3996,16 @@ S2.define('select2/dropdown',[

S2.define('select2/dropdown/search',[
'jquery',
'../utils'
], function ($, Utils) {
'../keys'
], function ($, KEYS) {
function Search () { }

Search.prototype.render = function (decorated) {
var $rendered = decorated.call(this);

var $search = $(
'<span class="select2-search select2-search--dropdown">' +
'<input class="select2-search__field" type="text" tabindex="-1"' +
'<input class="select2-search__field" type="text"' +
' autocomplete="off" autocorrect="off" autocapitalize="none"' +
' spellcheck="false" role="combobox" aria-autocomplete="list" aria-expanded="true" />' +
'</span>'
Expand Down Expand Up @@ -4035,21 +4040,19 @@ S2.define('select2/dropdown/search',[
});

this.$search.on('keyup input', function (evt) {
var key = evt.which;
if (key === KEYS.TAB) {
return;
}
self.handleSearch(evt);
});

container.on('open', function () {
self.$search.attr('tabindex', 0);
self.$search.attr('aria-owns', resultsId);
self.$search.trigger( 'focus' );

window.setTimeout(function () {
self.$search.trigger( 'focus' );
}, 0);
});

container.on('close', function () {
self.$search.attr('tabindex', -1);
self.$search.removeAttr('aria-activedescendant');
self.$search.removeAttr('aria-owns');
self.$search.val('');
Expand Down
23 changes: 14 additions & 9 deletions vendor/tribe-selectWoo/dist/js/selectWoo.full.min.js

Large diffs are not rendered by default.

0 comments on commit 3b6d19f

Please sign in to comment.