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

Commit 71cd3e9

Browse files
du6kara
authored andcommitted
fix(input): fix placeholder text being read twice by screen readers (#10524)
1 parent d3d0c5d commit 71cd3e9

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

src/components/input/input.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout, $mdGesture)
339339
var errorsSpacer = angular.element('<div class="md-errors-spacer">');
340340
element.after(errorsSpacer);
341341

342-
if (!containerCtrl.label) {
343-
$mdAria.expect(element, 'aria-label', attr.placeholder);
342+
var placeholderText = angular.isString(attr.placeholder) ? attr.placeholder.trim() : '';
343+
if (!containerCtrl.label && !placeholderText.length) {
344+
$mdAria.expect(element, 'aria-label');
344345
}
345346

346347
element.addClass('md-input');

src/components/input/input.spec.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ describe('md-input-container directive', function() {
477477
expect(label.textContent).toEqual('bar');
478478
});
479479

480-
it('should put an aria-label on the input when no label is present', inject(function($timeout) {
480+
it('should not copy placeholder text to aria-label on the input', inject(function($timeout) {
481481
var el = $compile(
482482
'<form name="form">' +
483483
' <md-input-container md-no-float>' +
@@ -489,21 +489,9 @@ describe('md-input-container directive', function() {
489489
$timeout.flush();
490490

491491
var input = el.find('input');
492-
expect(input.attr('aria-label')).toBe('baz');
492+
expect(input.attr('aria-label')).toBeUndefined();
493493
}));
494494

495-
it('should evaluate the placeholder expression before setting the aria-label', function() {
496-
pageScope.placeholder = 'baz';
497-
var el = $compile(
498-
'<form name="form">' +
499-
' <md-input-container md-no-float>' +
500-
' <input placeholder="{{placeholder}}" ng-model="foo" name="foo">' +
501-
' </md-input-container>' +
502-
'</form>')(pageScope);
503-
504-
expect(el.find('input').attr('aria-label')).toBe('baz');
505-
});
506-
507495
it('should put the container in "has value" state when input has a static value', function() {
508496
var scope = pageScope.$new();
509497
var template =

0 commit comments

Comments
 (0)