diff --git a/src/lib/select/select.spec.ts b/src/lib/select/select.spec.ts index a71efd75e250..08ed4d2e68e7 100644 --- a/src/lib/select/select.spec.ts +++ b/src/lib/select/select.spec.ts @@ -126,6 +126,7 @@ describe('MatSelect', () => { SelectWithGroups, SelectWithGroupsAndNgContainer, SelectWithFormFieldLabel, + SelectWithChangeEvent, ]); })); @@ -255,6 +256,16 @@ describe('MatSelect', () => { expect(select.getAttribute('aria-labelledby')).toBeFalsy(); }); + it('should not set `aria-labelledby` if there is no form field label', () => { + fixture.destroy(); + + const labelFixture = TestBed.createComponent(SelectWithChangeEvent); + labelFixture.detectChanges(); + select = labelFixture.debugElement.query(By.css('mat-select')).nativeElement; + + expect(select.getAttribute('aria-labelledby')).toBeFalsy(); + }); + it('should select options via the UP/DOWN arrow keys on a closed select', fakeAsync(() => { const formControl = fixture.componentInstance.control; const options = fixture.componentInstance.options.toArray(); diff --git a/src/lib/select/select.ts b/src/lib/select/select.ts index 0bb7f74def5e..16392766fc5b 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -1059,7 +1059,8 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit, // Note: we use `_getAriaLabel` here, because we want to check whether there's a // computed label. `this.ariaLabel` is only the user-specified label. - if (!this._parentFormField || this._getAriaLabel()) { + if (!this._parentFormField || !this._parentFormField._hasFloatingLabel() || + this._getAriaLabel()) { return null; }