Skip to content

Commit 2f981b7

Browse files
committed
fix(ngAria): don't add roles to native elements
don't add roles to textarea, button, select, summary, details, a and input Closes angular#14076 BREAKING CHANGE: albeit a small one that shouldn't affect a11y
1 parent 32feb2b commit 2f981b7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/ngAria/aria.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
221221
function shouldAttachRole(role, elem) {
222222
// if element does not have role attribute
223223
// AND element type is equal to role (if custom element has a type equaling shape) <-- remove?
224-
// AND element is not INPUT
225-
return !elem.attr('role') && (elem.attr('type') === role) && (elem[0].nodeName !== 'INPUT');
224+
// AND element is not in nodeBlackList
225+
return !elem.attr('role') && (elem.attr('type') === role) && !isNodeOneOf(elem, nodeBlackList);
226226
}
227227

228228
function getShape(attr, elem) {

test/ngAria/ariaSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ describe('$aria', function() {
272272
compileElement('<input type="range" ng-model="val"></div>');
273273
expect(element.attr('role')).toBe(undefined);
274274
});
275+
276+
they('should not add role to native $prop controls', {
277+
select: '<select type="checkbox" ng-model="val"></select>',
278+
textarea: '<textarea type="checkbox" ng-model="val"></textarea>',
279+
button: '<button ng-click="doClick()"></button>',
280+
summary: '<summary ng-click="doClick()"></summary>',
281+
details: '<details ng-click="doClick()"></details>',
282+
a: '<a ng-click="doClick()"></a>'
283+
}, function(tmpl) {
284+
var element = $compile(tmpl)(scope);
285+
expect(element.attr('role')).toBeUndefined();
286+
});
275287
});
276288

277289
describe('aria-checked when disabled', function() {

0 commit comments

Comments
 (0)