Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/autocomplete): auto-highlighted first option not display correctly if the floating label is disabled #14507

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
16 changes: 16 additions & 0 deletions src/material-experimental/mdc-autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,22 @@ describe('MDC-based MatAutocomplete', () => {
.toBe(false);
}));

it('should be able to preselect the first option when the floating label is disabled', fakeAsync(() => {
fixture.componentInstance.floatLabel = 'never';
fixture.componentInstance.trigger.autocomplete.autoActiveFirstOption = true;
fixture.detectChanges();

fixture.componentInstance.trigger.openPanel();
fixture.detectChanges();
zone.simulateZoneExit();
// Note: should not have a detectChanges call here
// in order for the test to fail when it's supposed to.

expect(overlayContainerElement.querySelectorAll('mat-option')[0].classList)
.withContext('Expected first option to be highlighted.')
.toContain('mat-mdc-option-active');
}));

it('should be able to configure preselecting the first option globally', fakeAsync(() => {
fixture.destroy();
TestBed.resetTestingModule();
Expand Down
1 change: 1 addition & 0 deletions src/material/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ export abstract class _MatAutocompleteTriggerBase
const wasOpen = this.panelOpen;
this._resetActiveItem();
this.autocomplete._setVisibility();
this._changeDetectorRef.detectChanges();

if (this.panelOpen) {
this._overlayRef!.updatePosition();
Expand Down
16 changes: 16 additions & 0 deletions src/material/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,22 @@ describe('MatAutocomplete', () => {
.toBe(false);
}));

it('should be able to preselect the first option when the floating label is disabled', fakeAsync(() => {
fixture.componentInstance.floatLabel = 'never';
fixture.componentInstance.trigger.autocomplete.autoActiveFirstOption = true;
fixture.detectChanges();

fixture.componentInstance.trigger.openPanel();
fixture.detectChanges();
zone.simulateZoneExit();
// Note: should not have a detectChanges call here
// in order for the test to fail when it's supposed to.

expect(overlayContainerElement.querySelectorAll('mat-option')[0].classList)
.withContext('Expected first option to be highlighted.')
.toContain('mat-active');
}));

it('should be able to configure preselecting the first option globally', fakeAsync(() => {
fixture.destroy();
TestBed.resetTestingModule();
Expand Down