fix(autocomplete): reposition the panel when the amount of options changes (#4469)

This commit is contained in:
Kristiyan Kostadinov
2018-06-29 19:43:58 +02:00
committed by Joey Perrott
parent 4a02bb1514
commit 2b80dbf583
2 changed files with 38 additions and 0 deletions
@@ -453,6 +453,11 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
switchMap(() => {
this._resetActiveItem();
this.autocomplete._setVisibility();
if (this.panelOpen) {
this._overlayRef!.updatePosition();
}
return this.panelClosingActions;
}),
// when the first closing event occurs...
+33
View File
@@ -1606,6 +1606,39 @@ describe('MatAutocomplete', () => {
subscription!.unsubscribe();
}));
it('should reposition the panel when the amount of options changes', fakeAsync(() => {
let formField = fixture.debugElement.query(By.css('.mat-form-field')).nativeElement;
let inputReference = formField.querySelector('.mat-form-field-flex');
let input = inputReference.querySelector('input');
formField.style.bottom = '100px';
formField.style.position = 'fixed';
typeInElement('Cali', input);
fixture.detectChanges();
tick();
zone.simulateZoneExit();
fixture.detectChanges();
const inputBottom = inputReference.getBoundingClientRect().bottom;
const panel = overlayContainerElement.querySelector('.mat-autocomplete-panel')!;
const panelTop = panel.getBoundingClientRect().top;
expect(Math.floor(inputBottom)).toBe(Math.floor(panelTop),
`Expected panel top to match input bottom when there is only one option.`);
typeInElement('', input);
fixture.detectChanges();
tick();
fixture.detectChanges();
const inputTop = inputReference.getBoundingClientRect().top;
const panelBottom = panel.getBoundingClientRect().bottom;
expect(Math.floor(inputTop)).toBe(Math.floor(panelBottom),
`Expected panel switch to the above position if the options no longer fit.`);
}));
});
describe('panel closing', () => {