From b43656c13c5528de9906b13cb98075c0463a75b3 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Wed, 14 Jan 2015 22:54:19 -0500 Subject: [PATCH] Added basic accessibility tests This adds basic tests to ensure that the selection is accessible by all users. This checks for common attributes, ensuring that the container is always keyboard accessible and follows ARIA guidelines. This also changes the base selection to create a common element so we don't need to repeat attributes and such across multiple selection containers. --- dist/js/i18n/cs.js | 1 + dist/js/select2.amd.full.js | 81 +++++++-------- dist/js/select2.amd.js | 81 +++++++-------- dist/js/select2.full.js | 81 +++++++-------- dist/js/select2.full.min.js | 4 +- dist/js/select2.js | 81 +++++++-------- dist/js/select2.min.js | 4 +- src/js/select2/selection/base.js | 23 ++++- src/js/select2/selection/multiple.js | 27 ++--- src/js/select2/selection/single.js | 31 ++---- tests/a11y/selection-tests.js | 146 +++++++++++++++++++++++++++ tests/a11y/selection.html | 39 +++++++ 12 files changed, 385 insertions(+), 214 deletions(-) create mode 100644 dist/js/i18n/cs.js create mode 100644 tests/a11y/selection-tests.js create mode 100644 tests/a11y/selection.html diff --git a/dist/js/i18n/cs.js b/dist/js/i18n/cs.js new file mode 100644 index 00000000..1117311c --- /dev/null +++ b/dist/js/i18n/cs.js @@ -0,0 +1 @@ +window.$=window.$||{},function(){$&&$.fn&&$.fn.select2&&$.fn.select2.amd&&(define=$.fn.select2.amd.define,require=$.fn.select2.amd.require),define("select2/i18n/cs",[],function(){function e(e,t){switch(e){case 2:return t?"dva":"dvě";case 3:return"tři";case 4:return"čtyři"}return""}return{errorLoading:function(){return"Výsledky nemohly být načteny."},inputTooLong:function(t){var n=t.input.length-t.maximum;return n==1?"Prosím zadejte o jeden znak méně":n<=4?"Prosím zadejte o "+e(n,!0)+" znaky méně":"Prosím zadejte o "+n+" znaků méně"},inputTooShort:function(t){var n=t.minimum-t.input.length;return n==1?"Prosím zadejte ještě jeden znak":n<=4?"Prosím zadejte ještě další "+e(n,!0)+" znaky":"Prosím zadejte ještě dalších "+n+" znaků"},loadingMore:function(){return"Načítají se další výsledky…"},maximumSelected:function(t){var n=t.maximum;return n==1?"Můžete zvolit jen jednu položku":n<=4?"Můžete zvolit maximálně "+e(n,!1)+" položky":"Můžete zvolit maximálně "+n+" položek"},noResults:function(){return"Nenalezeny žádné položky"},searching:function(){return"Vyhledávání…"}}}),require("jquery.select2"),$.fn.select2.amd={define:define,require:require}}(); \ No newline at end of file diff --git a/dist/js/select2.amd.full.js b/dist/js/select2.amd.full.js index 9e8e3179..63abd6c9 100644 --- a/dist/js/select2.amd.full.js +++ b/dist/js/select2.amd.full.js @@ -677,9 +677,10 @@ define('select2/keys',[ }); define('select2/selection/base',[ + 'jquery', '../utils', '../keys' -], function (Utils, KEYS) { +], function ($, Utils, KEYS) { function BaseSelection ($element, options) { this.$element = $element; this.options = options; @@ -690,7 +691,17 @@ define('select2/selection/base',[ Utils.Extend(BaseSelection, Utils.Observable); BaseSelection.prototype.render = function () { - throw new Error('The `render` method must be defined in child classes.'); + var $selection = $( + '' + ); + + $selection.attr('title', this.$element.attr('title')); + + this.$selection = $selection; + + return $selection; }; BaseSelection.prototype.bind = function (container, $container) { @@ -735,6 +746,14 @@ define('select2/selection/base',[ self._detachCloseHandler(container); }); + + container.on('enable', function () { + self.$selection.attr('tabindex', '0'); + }); + + container.on('disable', function () { + self.$selection.attr('tabindex', '-1'); + }); }; BaseSelection.prototype._attachCloseHandler = function (container) { @@ -787,10 +806,11 @@ define('select2/selection/base',[ }); define('select2/selection/single',[ + 'jquery', './base', '../utils', '../keys' -], function (BaseSelection, Utils, KEYS) { +], function ($, BaseSelection, Utils, KEYS) { function SingleSelection () { SingleSelection.__super__.constructor.apply(this, arguments); } @@ -798,21 +818,17 @@ define('select2/selection/single',[ Utils.Extend(SingleSelection, BaseSelection); SingleSelection.prototype.render = function () { - var $selection = $( - '