From 6e5d24d55ffd51f6dd3b285b82ef9a094855e69e Mon Sep 17 00:00:00 2001 From: anemirovsky Date: Fri, 28 May 2021 10:58:42 -0700 Subject: [PATCH] Various changes to get ARIA 1.1 compatibility. The following changes were made to match the spec at https://www.w3.org/TR/wai-aria-1.1/#combobox: * "combobox" role attribute added to the wrapper * "aria-haspopup" changed from "true" (which means "menu") to "listbox" to correctly match the role of the element containing the options * "aria-activedescendant" removed from the combobox element so it appears just on the element with the "textbox" role * "aria-multiline" set to "false" for the textbox element * "aria-owns" switched to "aria-controls" on the textbox element --- src/js/select2/selection/base.js | 7 +------ src/js/select2/selection/search.js | 7 ++++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/js/select2/selection/base.js b/src/js/select2/selection/base.js index 96702b2917..ee292f8d06 100644 --- a/src/js/select2/selection/base.js +++ b/src/js/select2/selection/base.js @@ -15,7 +15,7 @@ define([ BaseSelection.prototype.render = function () { var $selection = $( '' ); @@ -60,10 +60,6 @@ define([ } }); - container.on('results:focus', function (params) { - self.$selection.attr('aria-activedescendant', params.data._resultId); - }); - container.on('selection:update', function (params) { self.update(params.data); }); @@ -79,7 +75,6 @@ define([ container.on('close', function () { // When the dropdown is closed, aria-expanded="false" self.$selection.attr('aria-expanded', 'false'); - self.$selection.removeAttr('aria-activedescendant'); self.$selection.removeAttr('aria-owns'); // This needs to be delayed as the active element is the body when the diff --git a/src/js/select2/selection/search.js b/src/js/select2/selection/search.js index 35df5aa375..78f9867c8c 100644 --- a/src/js/select2/selection/search.js +++ b/src/js/select2/selection/search.js @@ -12,7 +12,8 @@ define([ '' ); @@ -33,14 +34,14 @@ define([ decorated.call(this, container, $container); container.on('open', function () { - self.$search.attr('aria-owns', resultsId); + self.$search.attr('aria-controls', resultsId); self.$search.trigger('focus'); }); container.on('close', function () { self.$search.val(''); self.$search.removeAttr('aria-activedescendant'); - self.$search.removeAttr('aria-owns'); + self.$search.removeAttr('aria-controls'); self.$search.trigger('focus'); });