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

Commit 471c225

Browse files
authored
fix(tooltip): use different attribute to track setting of aria-label (#10600)
1 parent 3d87453 commit 471c225

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/components/tooltip/tooltip.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $interpolate,
113113
// tooltip directive.
114114
if (
115115
(!parent.attr('aria-label') && !parent.attr('aria-labelledby')) ||
116-
parent.attr('aria-labelledby') === tooltipId
116+
parent.attr('md-labeled-by-tooltip')
117117
) {
118118
parent.attr('aria-label', interpolatedText);
119119

120-
// Set the `aria-labelledby` attribute if it has not already been set.
121-
if (!parent.attr('aria-labelledby')) {
122-
parent.attr('aria-labelledby', tooltipId);
120+
// Set the `md-labeled-by-tooltip` attribute if it has not already been set.
121+
if (!parent.attr('md-labeled-by-tooltip')) {
122+
parent.attr('md-labeled-by-tooltip', tooltipId);
123123
}
124124
}
125125
}

src/components/tooltip/tooltip.spec.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('MdTooltip Component', function() {
105105
);
106106

107107
expect(element.attr('aria-label')).toEqual('Tooltip');
108-
expect(element.attr('aria-labelledby')).toBeDefined();
108+
expect(element.attr('md-labeled-by-tooltip')).toBeDefined();
109109
});
110110

111111
it('should not label the parent if it already has a label', function() {
@@ -118,7 +118,7 @@ describe('MdTooltip Component', function() {
118118
);
119119

120120
expect(element.attr('aria-label')).toEqual('Button Label');
121-
expect(element.attr('aria-labelledby')).toBeUndefined();
121+
expect(element.attr('md-labeled-by-tooltip')).toBeUndefined();
122122
});
123123

124124
it('should not label the parent if it has already been labelled by ' +
@@ -143,12 +143,12 @@ describe('MdTooltip Component', function() {
143143
);
144144

145145
expect(element.attr('aria-label')).toBe('HELLO');
146-
expect(element.attr('aria-labelledby')).toBeDefined();
146+
expect(element.attr('md-labeled-by-tooltip')).toBeDefined();
147147
});
148148

149149
it('should update the aria-label when the interpolated value changes', function() {
150-
var ariaLabelledby;
151-
var ariaLabelledby2;
150+
var labeledByTooltip;
151+
var labeledByTooltip2;
152152

153153
buildTooltip(
154154
'<md-button>' +
@@ -161,16 +161,16 @@ describe('MdTooltip Component', function() {
161161
});
162162

163163
expect(element.attr('aria-label')).toBe('test 1');
164-
ariaLabelledby = element.attr('aria-labelledby');
165-
expect(ariaLabelledby).toBeDefined();
164+
labeledByTooltip = element.attr('md-labeled-by-tooltip');
165+
expect(labeledByTooltip).toBeDefined();
166166

167167
parentScope.$apply(function() {
168168
parentScope.testModel.ariaText = 'test 2';
169169
});
170170

171171
expect(element.attr('aria-label')).toBe('test 2');
172-
ariaLabelledby2 = element.attr('aria-labelledby');
173-
expect(ariaLabelledby2).toEqual(ariaLabelledby);
172+
labeledByTooltip2 = element.attr('md-labeled-by-tooltip');
173+
expect(labeledByTooltip2).toEqual(labeledByTooltip);
174174
});
175175

176176
it('should not update the parent aria-label when the interpolated' +
@@ -187,19 +187,19 @@ describe('MdTooltip Component', function() {
187187
});
188188

189189
expect(element.attr('aria-label')).toBe('Button Label');
190-
expect(element.attr('aria-labelledby')).toBeUndefined();
190+
expect(element.attr('md-labeled-by-tooltip')).toBeUndefined();
191191

192192
parentScope.$apply(function() {
193193
parentScope.testModel.ariaText = 'test 2';
194194
});
195195

196196
expect(element.attr('aria-label')).toBe('Button Label');
197-
expect(element.attr('aria-labelledby')).toBeUndefined();
197+
expect(element.attr('md-labeled-by-tooltip')).toBeUndefined();
198198
});
199199

200200
it('should not interpolate interpolated values', function() {
201-
var ariaLabelledby;
202-
var ariaLabelledby2;
201+
var labeledByTooltip;
202+
var labeledByTooltip2;
203203

204204
buildTooltip(
205205
'<md-button>' +
@@ -212,16 +212,16 @@ describe('MdTooltip Component', function() {
212212
});
213213

214214
expect(element.attr('aria-label')).toBe('test {{1+1}}');
215-
ariaLabelledby = element.attr('aria-labelledby');
216-
expect(ariaLabelledby).toBeDefined();
215+
labeledByTooltip = element.attr('md-labeled-by-tooltip');
216+
expect(labeledByTooltip).toBeDefined();
217217

218218
parentScope.$apply(function() {
219219
parentScope.testModel.ariaTest = 'test {{1+1336}}';
220220
});
221221

222222
expect(element.attr('aria-label')).toBe('test {{1+1336}}');
223-
ariaLabelledby2 = element.attr('aria-labelledby');
224-
expect(ariaLabelledby2).toEqual(ariaLabelledby);
223+
labeledByTooltip2 = element.attr('md-labeled-by-tooltip');
224+
expect(labeledByTooltip2).toEqual(labeledByTooltip);
225225
});
226226

227227
it('should not set parent to items with no pointer events',

0 commit comments

Comments
 (0)