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

Results respect disabled state of <option> #5560

Merged
merged 1 commit into from Jul 10, 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
7 changes: 6 additions & 1 deletion src/js/select2/results.js
Expand Up @@ -175,7 +175,12 @@ define([
'aria-selected': 'false'
};

if (data.disabled) {
var matches = window.Element.prototype.matches ||
window.Element.prototype.msMatchesSelector ||
window.Element.prototype.webkitMatchesSelector;

if ((data.element != null && matches.call(data.element, ':disabled')) ||
(data.element == null && data.disabled)) {
delete attrs['aria-selected'];
attrs['aria-disabled'] = 'true';
}
Expand Down
63 changes: 63 additions & 0 deletions tests/results/option-tests.js
@@ -0,0 +1,63 @@
module('Results - option');

var $ = require('jquery');

var Options = require('select2/options');

var Results = require('select2/results');

test('disabled property on option is respected - enabled', function (assert) {
var results = new Results($('<select></select>'), new Options({}));

var $option = $('<option></option>');
var option = results.option({
element: $option[0]
});

assert.notEqual(option.getAttribute('aria-disabled'), 'true');
});

test('disabled property on option is respected - disabled', function (assert) {
var results = new Results($('<select></select>'), new Options({}));

var $option = $('<option disabled></option>');
var option = results.option({
element: $option[0]
});

assert.equal(option.getAttribute('aria-disabled'), 'true');
});

test('disabled property on enabled optgroup is respected', function (assert) {
var results = new Results($('<select></select>'), new Options({}));

var $option = $('<optgroup></optgroup>');
var option = results.option({
element: $option[0]
});

assert.notEqual(option.getAttribute('aria-disabled'), 'true');
});

test('disabled property on disabled optgroup is respected', function (assert) {
var results = new Results($('<select></select>'), new Options({}));

var $option = $('<optgroup disabled></optgroup>');
var option = results.option({
element: $option[0]
});

assert.equal(option.getAttribute('aria-disabled'), 'true');
});

test('option in disabled optgroup is disabled', function (assert) {
var results = new Results($('<select></select>'), new Options({}));

var $option = $('<optgroup disabled><option></option></optgroup>')
.find('option');
var option = results.option({
element: $option[0]
});

assert.equal(option.getAttribute('aria-disabled'), 'true');
});
1 change: 1 addition & 0 deletions tests/unit-jq1.html
Expand Up @@ -82,6 +82,7 @@
<script src="options/width-tests.js" type="text/javascript"></script>

<script src="results/focusing-tests.js" type="text/javascript"></script>
<script src="results/option-tests.js" type="text/javascript"></script>

<script src="selection/allowClear-tests.js" type="text/javascript"></script>
<script src="selection/containerCss-tests.js" type="text/javascript"></script>
Expand Down
1 change: 1 addition & 0 deletions tests/unit-jq2.html
Expand Up @@ -82,6 +82,7 @@
<script src="options/width-tests.js" type="text/javascript"></script>

<script src="results/focusing-tests.js" type="text/javascript"></script>
<script src="results/option-tests.js" type="text/javascript"></script>

<script src="selection/allowClear-tests.js" type="text/javascript"></script>
<script src="selection/containerCss-tests.js" type="text/javascript"></script>
Expand Down
1 change: 1 addition & 0 deletions tests/unit-jq3.html
Expand Up @@ -82,6 +82,7 @@
<script src="options/width-tests.js" type="text/javascript"></script>

<script src="results/focusing-tests.js" type="text/javascript"></script>
<script src="results/option-tests.js" type="text/javascript"></script>

<script src="selection/allowClear-tests.js" type="text/javascript"></script>
<script src="selection/containerCss-tests.js" type="text/javascript"></script>
Expand Down