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

Commit 563b232

Browse files
Marcy SuttonThomasBurleson
authored andcommitted
fix(mdAria): apply aria-label to buttons correctly
Closes #8789 Closes #8793
1 parent 4caf220 commit 563b232

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

src/components/button/button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function MdButtonDirective($mdButtonInkRipple, $mdTheming, $mdAria, $timeout) {
142142
$mdButtonInkRipple.attach(scope, element);
143143

144144
// Use async expect to support possible bindings in the button label
145-
$mdAria.expectWithText(element, 'aria-label');
145+
$mdAria.expectWithoutText(element, 'aria-label');
146146

147147
// For anchor elements, we have to set tabindex manually when the
148148
// element is disabled

src/components/button/button.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ describe('md-button', function() {
3131
expect($log.warn).not.toHaveBeenCalled();
3232
}));
3333

34-
it('should expect an aria-label if element has text content', inject(function($compile, $rootScope, $log) {
34+
it('should not expect an aria-label if element has text content', inject(function($compile, $rootScope, $log) {
3535
spyOn($log, 'warn');
3636

3737
var button = $compile('<md-button>Hello</md-button>')($rootScope);
38-
expect(button.attr('aria-label')).toBe("Hello");
38+
expect(button.attr('aria-label')).toBeUndefined();
3939
expect($log.warn).not.toHaveBeenCalled();
4040
}));
4141

42-
it('should set an aria-label if the text content using bindings', inject(function($$rAF, $compile, $rootScope, $log, $timeout) {
42+
it('should not set an aria-label if the text content uses bindings', inject(function($$rAF, $compile, $rootScope, $log, $timeout) {
4343
spyOn($log, 'warn');
4444

4545
var scope = angular.extend($rootScope.$new(),{greetings : "Welcome"});
@@ -48,7 +48,7 @@ describe('md-button', function() {
4848
$rootScope.$apply();
4949
$$rAF.flush(); // needed for $mdAria.expectAsync()
5050

51-
expect(button.attr('aria-label')).toBe("Welcome");
51+
expect(button.attr('aria-label')).toBeUndefined();
5252
expect($log.warn).not.toHaveBeenCalled();
5353
}));
5454

src/components/tooltip/tooltip.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('<md-tooltip> directive', function() {
5252
'</md-button>'
5353
);
5454

55-
expect(element.attr('aria-label')).toBe("Hello");
55+
expect(element.text()).toBe("Hello");
5656
});
5757

5858
it('should label parent', function(){

src/core/services/aria/aria.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ function MdAriaService($$rAF, $log, $window, $interpolate) {
6565
return {
6666
expect: expect,
6767
expectAsync: expectAsync,
68-
expectWithText: expectWithText
68+
expectWithText: expectWithText,
69+
expectWithoutText: expectWithoutText
6970
};
7071

7172
/**
@@ -116,6 +117,15 @@ function MdAriaService($$rAF, $log, $window, $interpolate) {
116117
}
117118
}
118119

120+
function expectWithoutText(element, attrName) {
121+
var content = getText(element);
122+
var hasBinding = content.indexOf($interpolate.startSymbol()) > -1;
123+
124+
if ( !hasBinding && !content) {
125+
expect(element, attrName, content);
126+
}
127+
}
128+
119129
function getText(element) {
120130
element = element[0] || element;
121131
var walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null, false);

src/core/services/aria/aria.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ describe('$mdAria service', function() {
3939
expect($log.warn).toHaveBeenCalled();
4040
}));
4141

42+
it('should not warn if element has text', inject(function($compile, $rootScope, $log, $mdAria) {
43+
spyOn($log, 'warn');
44+
var button = $compile('<button>Text</button>')($rootScope);
45+
46+
$mdAria.expectWithoutText(button, 'aria-label');
47+
48+
expect($log.warn).not.toHaveBeenCalled();
49+
}));
50+
51+
it('should warn if control is missing text', inject(function($compile, $rootScope, $log, $mdAria) {
52+
spyOn($log, 'warn');
53+
var radioButton = $compile('<md-radio-button>Text</md-radio-button>')($rootScope);
54+
55+
$mdAria.expectWithText(radioButton, 'aria-label');
56+
57+
expect($log.warn).not.toHaveBeenCalled();
58+
}));
59+
4260
it('should not warn if child element has attribute', inject(function($compile, $rootScope, $log, $mdAria) {
4361
spyOn($log, 'warn');
4462
var button = $compile('<button><md-icon aria-label="text"></md-icon></button>')($rootScope);

0 commit comments

Comments
 (0)