Sfoglia il codice sorgente

Speak results on selection

This closes https://github.com/select2/select2/issues/3735
This closes https://github.com/select2/select2/pull/3821
Jono Mingard 9 anni fa
parent
commit
9fae3d74e3

+ 2 - 1
src/js/select2/results.js

@@ -37,7 +37,8 @@ define([
     this.hideLoading();
 
     var $message = $(
-      '<li role="treeitem" class="select2-results__option"></li>'
+      '<li role="treeitem" aria-live="assertive"' +
+      ' class="select2-results__option"></li>'
     );
 
     var message = this.options.get('translations').get(params.message);

+ 1 - 1
src/js/select2/selection/base.js

@@ -15,7 +15,7 @@ define([
   BaseSelection.prototype.render = function () {
     var $selection = $(
       '<span class="select2-selection" role="combobox" ' +
-      'aria-autocomplete="list" aria-haspopup="true" aria-expanded="false">' +
+      ' aria-haspopup="true" aria-expanded="false">' +
       '</span>'
     );
 

+ 6 - 1
src/js/select2/selection/search.js

@@ -12,7 +12,7 @@ define([
       '<li class="select2-search select2-search--inline">' +
         '<input class="select2-search__field" type="search" tabindex="-1"' +
         ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
-        ' spellcheck="false" role="textbox" />' +
+        ' spellcheck="false" role="textbox" aria-autocomplete="list" />' +
       '</li>'
     );
 
@@ -37,6 +37,7 @@ define([
 
     container.on('close', function () {
       self.$search.val('');
+      self.$search.removeAttr('aria-activedescendant');
       self.$search.trigger('focus');
     });
 
@@ -54,6 +55,10 @@ define([
       self.$search.trigger('focus');
     });
 
+    container.on('results:focus', function (params) {
+      self.$search.attr('aria-activedescendant', params.id);
+    });
+
     this.$selection.on('focusin', '.select2-search--inline', function (evt) {
       self.trigger('focus', evt);
     });