From bbbec18e5a9d79dd2957ddaad36993f80b879ce4 Mon Sep 17 00:00:00 2001 From: Marcy Sutton Date: Tue, 10 Feb 2015 16:05:30 -0800 Subject: [PATCH] fix(mdIcon): support aria-label on mdRadioButton --- src/components/icon/icon.js | 14 +++++++++++--- src/components/icon/icon.spec.js | 8 ++++++++ .../radioButton/demoBasicUsage/index.html | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/components/icon/icon.js b/src/components/icon/icon.js index a95daebf09c..288325b9c2f 100644 --- a/src/components/icon/icon.js +++ b/src/components/icon/icon.js @@ -66,10 +66,8 @@ function mdIconDirective($mdIcon, $mdAria, $log) { function postLink(scope, element, attr) { var ariaLabel = attr.alt || scope.fontIcon || scope.svgIcon; var attrName = attr.$normalize(attr.$attr.mdSvgIcon || attr.$attr.mdSvgSrc || ''); - var parentEl = element.parent(); - var parentLabel = parentEl.attr('aria-label') || parentEl.text(); - if (!parentLabel && attr.alt !== '') { + if (attr.alt != '' && !parentsHaveText()) { $mdAria.expect(element, 'aria-label', ariaLabel); $mdAria.expect(element, 'role', 'img'); } else { @@ -90,6 +88,16 @@ function mdIconDirective($mdIcon, $mdAria, $log) { }); } + function parentsHaveText() { + var parent = element.parent(); + if (parent.attr('aria-label') || parent.text()) { + return true; + } + else if(parent.parent().attr('aria-label') || parent.parent().text()) { + return true; + } + return false; + } } } diff --git a/src/components/icon/icon.spec.js b/src/components/icon/icon.spec.js index 296525e4952..ddffdbcd63c 100644 --- a/src/components/icon/icon.spec.js +++ b/src/components/icon/icon.spec.js @@ -63,6 +63,14 @@ describe('mdIcon directive', function() { it('should apply aria-hidden="true" when parent has valid label', function() { el = make(''); expect(el.find('md-icon').attr('aria-hidden')).toEqual('true'); + + el = make(' '+ + '
'+ + '
'+ + ' '+ + '
'); + + expect(el.find('md-icon').attr('aria-hidden')).toEqual('true'); }); it('should apply aria-hidden="true" when parent has text content', function() { diff --git a/src/components/radioButton/demoBasicUsage/index.html b/src/components/radioButton/demoBasicUsage/index.html index bb1cb1eeebf..9b196db27c2 100644 --- a/src/components/radioButton/demoBasicUsage/index.html +++ b/src/components/radioButton/demoBasicUsage/index.html @@ -38,7 +38,7 @@ - +