Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe('MatSelect', () => {
SelectWithGroups,
SelectWithGroupsAndNgContainer,
SelectWithFormFieldLabel,
SelectWithChangeEvent,
]);
}));

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down