Skip to content

Commit 947d3e8

Browse files
Lindsorandrewseguin
authored andcommitted
fix(select) aria-labelledby (#7022)
aria-labelledby must not be in the DOM if it is empty this causes accessability bugs.
1 parent 2129b7a commit 947d3e8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/lib/select/select.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,15 @@ describe('MatSelect', () => {
18021802
expect(select.getAttribute('aria-labelledby')).toBe('myLabelId');
18031803
});
18041804

1805+
it('should not have aria-labelledby in the DOM if it`s not specified', async(() => {
1806+
1807+
fixture.detectChanges();
1808+
1809+
fixture.whenStable().then(() => {
1810+
expect(select.hasAttribute('aria-labelledby')).toBeFalsy();
1811+
});
1812+
}));
1813+
18051814
it('should set the tabindex of the select to 0 by default', () => {
18061815
expect(select.getAttribute('tabindex')).toEqual('0');
18071816
});

src/lib/select/select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
371371
@Input('aria-label') ariaLabel: string = '';
372372

373373
/** Input that can be used to specify the `aria-labelledby` attribute. */
374-
@Input('aria-labelledby') ariaLabelledby: string = '';
374+
@Input('aria-labelledby') ariaLabelledby: string;
375375

376376
/** Unique id of the element. */
377377
@Input()

0 commit comments

Comments
 (0)