Skip to content

Commit

Permalink
Set aria-controls instead of aria-owns on search boxes
Browse files Browse the repository at this point in the history
In ARIA 1.1, there was a switch to use `aria-controls` on the search
box to point to the results list instead of using `aria-owns`. This
is required because the `combobox`, in our case the selection
container, should have the `aria-owns` attribute pointing to the
results list. And because only one elment can own another element,
we must fall back to `aria-controls` to represent that relationship.

The tests have also been adjusted to reflect this new discovery.
  • Loading branch information
kevin-brown committed Jul 26, 2019
1 parent ce693bb commit db68550
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/js/select2/dropdown/search.js
Expand Up @@ -50,7 +50,7 @@ define([

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

self.$search.trigger('focus');

Expand All @@ -61,7 +61,7 @@ define([

container.on('close', function () {
self.$search.attr('tabindex', -1);
self.$search.removeAttr('aria-owns');
self.$search.removeAttr('aria-controls');
self.$search.removeAttr('aria-activedescendant');

self.$search.val('');
Expand Down
4 changes: 2 additions & 2 deletions src/js/select2/selection/search.js
Expand Up @@ -34,13 +34,13 @@ 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-owns');
self.$search.removeAttr('aria-controls');
self.$search.removeAttr('aria-activedescendant');
self.$search.trigger('focus');
});
Expand Down
14 changes: 7 additions & 7 deletions tests/dropdown/search-a11y-tests.js
Expand Up @@ -128,7 +128,7 @@ test('aria-activedescendant should be removed when closed', function (assert) {
);
});

test('aria-owns should not be set initiailly', function (assert) {
test('aria-controls should not be set initiailly', function (assert) {
var $select = $('#qunit-fixture .single');

var dropdown = new DropdownSearch($select, options);
Expand All @@ -140,12 +140,12 @@ test('aria-owns should not be set initiailly', function (assert) {
var $search = $dropdown.find('input');

assert.ok(
!$search.attr('aria-owns'),
!$search.attr('aria-controls'),
'The search box should not point to the results when it is first rendered'
);
});

test('aria-owns should be set when opened', function (assert) {
test('aria-controls should be set when opened', function (assert) {
var $select = $('#qunit-fixture .single');

var dropdown = new DropdownSearch($select, options);
Expand All @@ -159,12 +159,12 @@ test('aria-owns should be set when opened', function (assert) {
container.trigger('open');

assert.ok(
$search.attr('aria-owns'),
$search.attr('aria-controls'),
'The search should point to the results when it is opened'
);
});

test('aria-owns should be removed when closed', function (assert) {
test('aria-controls should be removed when closed', function (assert) {
var $select = $('#qunit-fixture .single');

var dropdown = new DropdownSearch($select, options);
Expand All @@ -174,12 +174,12 @@ test('aria-owns should be removed when closed', function (assert) {
dropdown.bind(container, $('<span></span>'));

var $search = $dropdown.find('input');
$search.attr('aria-owns', 'something');
$search.attr('aria-controls', 'something');

container.trigger('close');

assert.ok(
!$search.attr('aria-owns'),
!$search.attr('aria-controls'),
'There are no results for the search box to point to when it is closed'
);
});
14 changes: 7 additions & 7 deletions tests/selection/search-a11y-tests.js
Expand Up @@ -148,7 +148,7 @@ test('aria-activedescendant should be removed when closed', function (assert) {
);
});

test('aria-owns should not be set initiailly', function (assert) {
test('aria-controls should not be set initiailly', function (assert) {
var $select = $('#qunit-fixture .multiple');

var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
Expand All @@ -164,12 +164,12 @@ test('aria-owns should not be set initiailly', function (assert) {
var $search = $selection.find('input');

assert.ok(
!$search.attr('aria-owns'),
!$search.attr('aria-controls'),
'The search box should not point to the results when it is first rendered'
);
});

test('aria-owns should be set when opened', function (assert) {
test('aria-controls should be set when opened', function (assert) {
var $select = $('#qunit-fixture .multiple');

var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
Expand All @@ -187,12 +187,12 @@ test('aria-owns should be set when opened', function (assert) {
container.trigger('open');

assert.ok(
$search.attr('aria-owns'),
$search.attr('aria-controls'),
'The search should point to the results when it is opened'
);
});

test('aria-owns should be removed when closed', function (assert) {
test('aria-controls should be removed when closed', function (assert) {
var $select = $('#qunit-fixture .multiple');

var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
Expand All @@ -206,12 +206,12 @@ test('aria-owns should be removed when closed', function (assert) {
selection.update([]);

var $search = $selection.find('input');
$search.attr('aria-owns', 'something');
$search.attr('aria-controls', 'something');

container.trigger('close');

assert.ok(
!$search.attr('aria-owns'),
!$search.attr('aria-controls'),
'There are no results for the search box to point to when it is closed'
);
});

0 comments on commit db68550

Please sign in to comment.