From 6fd9c76bfb4ab7750d68e0917e7a3263cc1a2d98 Mon Sep 17 00:00:00 2001 From: mohamed amr Date: Sun, 28 Feb 2016 22:01:39 +0200 Subject: [PATCH] fix(ngAria): don't add roles to native elements prevent ngAria from attaching roles to textarea, button, select, summary, details, a and input Closes #14076 BREAKING CHANGE: Curreny behavior is that ngAria don't attach roles to input elements but it does so to other native controls. so this change will prevent ngAria from attaching roles to native elements like (textrea, select, button, etc) and it will only attach roles to non-native controls. and this should not affect accessibility, because native inputs are accessible by default. (albeit a small one that shouldn't affect a11y) --- src/ngAria/aria.js | 4 ++-- test/ngAria/ariaSpec.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ngAria/aria.js b/src/ngAria/aria.js index 400d951e2bc0..f2980a413a9a 100644 --- a/src/ngAria/aria.js +++ b/src/ngAria/aria.js @@ -221,8 +221,8 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) { function shouldAttachRole(role, elem) { // if element does not have role attribute // AND element type is equal to role (if custom element has a type equaling shape) <-- remove? - // AND element is not INPUT - return !elem.attr('role') && (elem.attr('type') === role) && (elem[0].nodeName !== 'INPUT'); + // AND element is not in nodeBlackList + return !elem.attr('role') && (elem.attr('type') === role) && !isNodeOneOf(elem, nodeBlackList); } function getShape(attr, elem) { diff --git a/test/ngAria/ariaSpec.js b/test/ngAria/ariaSpec.js index 37c4f17bf1d8..ec1d29e560ce 100644 --- a/test/ngAria/ariaSpec.js +++ b/test/ngAria/ariaSpec.js @@ -272,6 +272,18 @@ describe('$aria', function() { compileElement(''); expect(element.attr('role')).toBe(undefined); }); + + they('should not add role to native $prop controls', { + select: '', + textarea: '', + button: '', + summary: '', + details: '
', + a: '' + }, function(tmpl) { + var element = $compile(tmpl)(scope); + expect(element.attr('role')).toBeUndefined(); + }); }); describe('aria-checked when disabled', function() {