Skip to content

Commit

Permalink
fix(slide-toggle): label not being read out by screen reader on IE (#…
Browse files Browse the repository at this point in the history
…14259)

Fixes the label of a slide toggle not being read out by NVDA on IE, because the `label` element isn't pointing to the `input`.
  • Loading branch information
crisbeto authored and jelbourn committed Dec 3, 2018
1 parent da3776f commit 5264804
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/lib/slide-toggle/slide-toggle.html
@@ -1,5 +1,4 @@
<label class="mat-slide-toggle-label" #label>

<label [attr.for]="inputId" class="mat-slide-toggle-label" #label>
<div #toggleBar class="mat-slide-toggle-bar"
[class.mat-slide-toggle-bar-no-side-margin]="!labelContent.textContent || !labelContent.textContent.trim()">

Expand Down
6 changes: 6 additions & 0 deletions src/lib/slide-toggle/slide-toggle.spec.ts
Expand Up @@ -249,6 +249,12 @@ describe('MatSlideToggle without forms', () => {
expect(inputElement.hasAttribute('aria-labelledby')).toBeFalsy();
});

it('should set the `for` attribute to the id of the input element', () => {
expect(labelElement.getAttribute('for')).toBeTruthy();
expect(inputElement.getAttribute('id')).toBeTruthy();
expect(labelElement.getAttribute('for')).toBe(inputElement.getAttribute('id'));
});

it('should emit the new values properly', fakeAsync(() => {
labelElement.click();
fixture.detectChanges();
Expand Down

0 comments on commit 5264804

Please sign in to comment.