diff --git a/src/js/select2/results.js b/src/js/select2/results.js
index b56f8d3b..e76d106b 100644
--- a/src/js/select2/results.js
+++ b/src/js/select2/results.js
@@ -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';
}
diff --git a/tests/results/option-tests.js b/tests/results/option-tests.js
new file mode 100644
index 00000000..6ffbb373
--- /dev/null
+++ b/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($(''), new Options({}));
+
+ var $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($(''), new Options({}));
+
+ var $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($(''), new Options({}));
+
+ var $option = $('');
+ 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($(''), new Options({}));
+
+ var $option = $('');
+ 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($(''), new Options({}));
+
+ var $option = $('')
+ .find('option');
+ var option = results.option({
+ element: $option[0]
+ });
+
+ assert.equal(option.getAttribute('aria-disabled'), 'true');
+});
\ No newline at end of file
diff --git a/tests/unit-jq1.html b/tests/unit-jq1.html
index 7de1bfa2..ce66eee6 100644
--- a/tests/unit-jq1.html
+++ b/tests/unit-jq1.html
@@ -82,6 +82,7 @@
+
diff --git a/tests/unit-jq2.html b/tests/unit-jq2.html
index eb7eb12d..b1c2cf33 100644
--- a/tests/unit-jq2.html
+++ b/tests/unit-jq2.html
@@ -82,6 +82,7 @@
+
diff --git a/tests/unit-jq3.html b/tests/unit-jq3.html
index a14fa9e6..687eafc2 100644
--- a/tests/unit-jq3.html
+++ b/tests/unit-jq3.html
@@ -82,6 +82,7 @@
+