Skip to content

fix(form-field): add aria-owns to label element #6683

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

Merged
merged 1 commit into from
Sep 1, 2017
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
3 changes: 3 additions & 0 deletions src/lib/form-field/form-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
<ng-content></ng-content>

<span class="mat-input-placeholder-wrapper mat-form-field-placeholder-wrapper">
<!-- We add aria-owns as a workaround for an issue in JAWS & NVDA where the label isn't
read if it comes before the control in the DOM. -->
<label class="mat-input-placeholder mat-form-field-placeholder"
[attr.for]="_control.id"
[attr.aria-owns]="_control.id"
[class.mat-empty]="_control.empty && !_shouldAlwaysFloat"
[class.mat-form-field-empty]="_control.empty && !_shouldAlwaysFloat"
[class.mat-float]="_canPlaceholderFloat"
Expand Down
12 changes: 12 additions & 0 deletions src/lib/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ describe('MdInput without forms', function () {
expect(inputElement.id).toEqual(labelElement.getAttribute('for'));
});

it('should add aria-owns to the label for the associated control', () => {
let fixture = TestBed.createComponent(MdInputTextTestController);
fixture.detectChanges();

const inputElement: HTMLInputElement =
fixture.debugElement.query(By.css('input')).nativeElement;
const labelElement: HTMLInputElement =
fixture.debugElement.query(By.css('label')).nativeElement;

expect(labelElement.getAttribute('aria-owns')).toBe(inputElement.id);
});

it('should not overwrite existing id', () => {
let fixture = TestBed.createComponent(MdInputWithId);
fixture.detectChanges();
Expand Down