Skip to content

Commit 4191b4d

Browse files
authored
fix(form-field): add aria-owns to label element (#6683)
1 parent fbce67d commit 4191b4d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/lib/form-field/form-field.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
<ng-content></ng-content>
99

1010
<span class="mat-input-placeholder-wrapper mat-form-field-placeholder-wrapper">
11+
<!-- We add aria-owns as a workaround for an issue in JAWS & NVDA where the label isn't
12+
read if it comes before the control in the DOM. -->
1113
<label class="mat-input-placeholder mat-form-field-placeholder"
1214
[attr.for]="_control.id"
15+
[attr.aria-owns]="_control.id"
1316
[class.mat-empty]="_control.empty && !_shouldAlwaysFloat"
1417
[class.mat-form-field-empty]="_control.empty && !_shouldAlwaysFloat"
1518
[class.mat-float]="_canPlaceholderFloat"

src/lib/input/input.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ describe('MdInput without forms', function () {
224224
expect(inputElement.id).toEqual(labelElement.getAttribute('for'));
225225
});
226226

227+
it('should add aria-owns to the label for the associated control', () => {
228+
let fixture = TestBed.createComponent(MdInputTextTestController);
229+
fixture.detectChanges();
230+
231+
const inputElement: HTMLInputElement =
232+
fixture.debugElement.query(By.css('input')).nativeElement;
233+
const labelElement: HTMLInputElement =
234+
fixture.debugElement.query(By.css('label')).nativeElement;
235+
236+
expect(labelElement.getAttribute('aria-owns')).toBe(inputElement.id);
237+
});
238+
227239
it('should not overwrite existing id', () => {
228240
let fixture = TestBed.createComponent(MdInputWithId);
229241
fixture.detectChanges();

0 commit comments

Comments
 (0)