Skip to content

Commit b8f8822

Browse files
committed
fix(ngAria): don't add roles to native elements
don't add roles to (textarea, button, select, summary, details, a, input) fix angular#14076
1 parent 32feb2b commit b8f8822

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-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

+31
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,37 @@ describe('$aria', function() {
272272
compileElement('<input type="range" ng-model="val"></div>');
273273
expect(element.attr('role')).toBe(undefined);
274274
});
275+
276+
it('should not add a role to a native select', function() {
277+
compileElement('<select type="checkbox" ng-model="val"></select>');
278+
expect(element.attr('role')).toBe(undefined);
279+
});
280+
281+
it('should not add a role to a native textarea element', function() {
282+
compileElement('<textarea type="checkbox" ng-model="val"></textarea>');
283+
expect(element.attr('role')).toBe(undefined);
284+
});
285+
286+
it('should not add a role to a native button element', function() {
287+
compileElement('<button ng-click="doClick()"></button>');
288+
expect(element.attr('role')).toBe(undefined);
289+
});
290+
291+
it('should not add a role to a native summary element', function() {
292+
compileElement('<summary ng-click="doClick()"></summary>');
293+
expect(element.attr('role')).toBe(undefined);
294+
});
295+
296+
it('should not add a role to a native details element', function() {
297+
compileElement('<details ng-click="doClick()"></details>');
298+
expect(element.attr('role')).toBe(undefined);
299+
});
300+
301+
it('should not add a role to a native a element', function() {
302+
compileElement('<a ng-click="doClick()"></a>');
303+
expect(element.attr('role')).toBe(undefined);
304+
});
305+
275306
});
276307

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

0 commit comments

Comments
 (0)