Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(mdIcon): support aria-label on mdRadioButton
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcy Sutton committed Feb 11, 2015
1 parent 5d29aae commit bbbec18
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/components/icon/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/components/icon/icon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ describe('mdIcon directive', function() {
it('should apply aria-hidden="true" when parent has valid label', function() {
el = make('<button aria-label="Android"><md-icon md-svg-icon="android"></md-icon></button>');
expect(el.find('md-icon').attr('aria-hidden')).toEqual('true');

el = make('<md-radio-button aria-label="avatar 2" role="radio"> '+
'<div class="md-container"></div> '+
'<div class="md-label"> '+
'<md-icon md-svg-icon="android"></md-icon> '+
'</div></md-radio-button>');

expect(el.find('md-icon').attr('aria-hidden')).toEqual('true');
});

it('should apply aria-hidden="true" when parent has text content', function() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/radioButton/demoBasicUsage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<md-radio-button ng-repeat="it in avatarData"
ng-value="it.value"
aria-label="{{it.title}}">
<md-icon md-svg-icon="{{it.id}}" alt="{{it.title}}"></md-icon>
<md-icon md-svg-icon="{{it.id}}"></md-icon>
</md-radio-button>
</md-radio-group>
</form>

0 comments on commit bbbec18

Please sign in to comment.