Skip to content

Commit 136dfa8

Browse files
crisbetojelbourn
authored andcommitted
fix(slide-toggle): label not being read out by screen reader on IE (#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`.
1 parent 031045c commit 136dfa8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/lib/slide-toggle/slide-toggle.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<label class="mat-slide-toggle-label" #label>
2-
1+
<label [attr.for]="inputId" class="mat-slide-toggle-label" #label>
32
<div #toggleBar class="mat-slide-toggle-bar"
43
[class.mat-slide-toggle-bar-no-side-margin]="!labelContent.textContent || !labelContent.textContent.trim()">
54

src/lib/slide-toggle/slide-toggle.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ describe('MatSlideToggle without forms', () => {
249249
expect(inputElement.hasAttribute('aria-labelledby')).toBeFalsy();
250250
});
251251

252+
it('should set the `for` attribute to the id of the input element', () => {
253+
expect(labelElement.getAttribute('for')).toBeTruthy();
254+
expect(inputElement.getAttribute('id')).toBeTruthy();
255+
expect(labelElement.getAttribute('for')).toBe(inputElement.getAttribute('id'));
256+
});
257+
252258
it('should emit the new values properly', fakeAsync(() => {
253259
labelElement.click();
254260
fixture.detectChanges();

0 commit comments

Comments
 (0)