diff --git a/src/core/services/aria/aria.js b/src/core/services/aria/aria.js index 40e96ae016c..eb360c2d3e2 100644 --- a/src/core/services/aria/aria.js +++ b/src/core/services/aria/aria.js @@ -13,14 +13,15 @@ function AriaService($$rAF, $log) { }; /** - * Check if expected attribute has been specified on the target element + * Check if expected attribute has been specified on the target element or child * @param element * @param attrName * @param {optional} defaultValue What to set the attr to if no value is found */ function expect(element, attrName, defaultValue) { var node = element[0]; - if (!node.hasAttribute(attrName)) { + + if (!node.hasAttribute(attrName) && !childHasAttribute(node, attrName)) { defaultValue = angular.isString(defaultValue) && defaultValue.trim() || ''; if (defaultValue.length) { @@ -47,5 +48,28 @@ function AriaService($$rAF, $log) { }); } + function childHasAttribute(node, attrName) { + var hasChildren = node.hasChildNodes(), + childHasAttribute = false; + + function isHidden(el) { + var style = el.currentStyle ? el.currentStyle : + getComputedStyle(el); + return (style.display === 'none'); + } + + if(hasChildren) { + var children = node.childNodes; + for(var i=0; i')($rootScope); + + $mdAria.expect(button, 'aria-label'); + + expect($log.warn).toHaveBeenCalled(); + })); + + it('should not warn if child element has attribute', inject(function($compile, $rootScope, $log, $mdAria) { + spyOn($log, 'warn'); + var button = $compile('')($rootScope); + + $mdAria.expect(button, 'aria-label'); + + expect($log.warn).not.toHaveBeenCalled(); + })); + + it('should warn if child with attribute is hidden', inject(function($compile, $rootScope, $log, $mdAria) { + spyOn($log, 'warn'); + var container = angular.element(document.body); + var button = $compile('')($rootScope); + + container.append(button); + + $mdAria.expect(button, 'aria-label'); + + expect($log.warn).toHaveBeenCalled(); + + button.remove(); + + })); + }); + +});