Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirror disabled state through aria-disabled on selection #5579

Merged
merged 1 commit into from Jul 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/js/select2/selection/base.js
Expand Up @@ -29,6 +29,7 @@ define([

$selection.attr('title', this.$element.attr('title'));
$selection.attr('tabindex', this._tabindex);
$selection.attr('aria-disabled', 'false');

this.$selection = $selection;

Expand Down Expand Up @@ -88,10 +89,12 @@ define([

container.on('enable', function () {
self.$selection.attr('tabindex', self._tabindex);
self.$selection.attr('aria-disabled', 'false');
});

container.on('disable', function () {
self.$selection.attr('tabindex', '-1');
self.$selection.attr('aria-disabled', 'true');
});
};

Expand Down
32 changes: 32 additions & 0 deletions tests/a11y/selection-tests.js
Expand Up @@ -131,6 +131,38 @@ test('a custom tabindex is copied', function (assert) {
);
});

test('aria-disabled should reflected disabled state', function (assert) {
var $select = $('#qunit-fixture .single');

var selection = new BaseSelection($select, options);
var $selection = selection.render();

var container = new MockContainer();
selection.bind(container, $('<span></span>'));

assert.equal(
$selection.attr('aria-disabled'),
'false',
'The tab index should match the original tab index'
);

container.trigger('disable');

assert.equal(
$selection.attr('aria-disabled'),
'true',
'The selection should be dropped out of the tab order when disabled'
);

container.trigger('enable');

assert.equal(
$selection.attr('aria-disabled'),
'false',
'The tab index should be restored when re-enabled'
);
});

module('Accessibility - Single');

test('aria-labelledby should match the rendered container', function (assert) {
Expand Down