Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(input): required asterisk being read out by screen readers #6277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lib/input/input-container.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
*ngIf="_hasPlaceholder()">
<ng-content select="md-placeholder, mat-placeholder"></ng-content>
{{_mdInputChild.placeholder}}
<span class="mat-placeholder-required" *ngIf="!hideRequiredMarker && _mdInputChild.required">*</span>
<span
class="mat-placeholder-required"
aria-hidden="true"
*ngIf="!hideRequiredMarker && _mdInputChild.required">*</span>
</label>
</span>
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/lib/input/input-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,15 @@ describe('MdInputContainer without forms', function () {
expect(el.nativeElement.textContent).toMatch(/hello\s+\*/g);
});

it('should hide the required star from screen readers', () => {
let fixture = TestBed.createComponent(MdInputContainerPlaceholderRequiredTestComponent);
fixture.detectChanges();

let el = fixture.debugElement.query(By.css('.mat-placeholder-required')).nativeElement;

expect(el.getAttribute('aria-hidden')).toBe('true');
});

it('hide placeholder required star when set to hide the required marker', () => {
let fixture = TestBed.createComponent(MdInputContainerPlaceholderRequiredTestComponent);
fixture.detectChanges();
Expand Down