Skip to content

Commit

Permalink
XWIKI-22492: Livedata filter options are misread (#3700)
Browse files Browse the repository at this point in the history
* Added a bit of semantics on the options
* Added a live update region for the state of the `active` option.
* Fixed when navigating with arrows and validating with Enter.
  • Loading branch information
Sereza7 authored Jan 13, 2025
1 parent 9b506ab commit 88e3e7d
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ define('xwiki-selectize', [
'xwiki-events-bridge'
], function($, Selectize, l10n) {
var optionTemplate = [
'<div class="xwiki-selectize-option" data-value="">',
'<div class="xwiki-selectize-option" role="option" aria-selected="false" data-value="">',
'<span class="xwiki-selectize-option-icon"></span>',
'<span class="xwiki-selectize-option-label"></span>',
'</div>'
Expand Down Expand Up @@ -203,6 +203,25 @@ define('xwiki-selectize', [
});
}
}
let oldOnOptionSelect = this.selectize.onOptionSelect;
this.selectize.onOptionSelect = function(...args) {
const result = oldOnOptionSelect.apply(this, args);
// clear aria-selected state on all previously selected elements first
this.get$('dropdown').find('.option').attr('aria-selected','false');
// then set the aria-selected state of the newly selected element.
this.get$('dropdown').find('.selected').attr('aria-selected','true');
return result;
}
let oldSetActiveOption = this.selectize.setActiveOption;
this.selectize.setActiveOption = function(option, ...args) {
this.liveRegion?.text($(option).text());
return oldSetActiveOption.call(this, option, ...args);
}
// Create a live region to store the value of the currently active option.
this.selectize.liveRegion = $('<span>');
this.selectize.liveRegion.attr('aria-live', 'assertive');
this.selectize.liveRegion.addClass('sr-only');
this.selectize.get$('input').after(this.selectize.liveRegion);
setDropDownAlignment(this.selectize);
if (this.selectize.settings.takeInputWidth) {
this.selectize.get$('control').width($(this).data('initialWidth'));
Expand Down

0 comments on commit 88e3e7d

Please sign in to comment.