fix(autocomplete): not propagating same model value when reset while open (#13634)

This commit is contained in:
Kristiyan Kostadinov
2018-10-19 17:17:45 +02:00
committed by Joey Perrott
parent fa6e46da98
commit 8d98375237
2 changed files with 29 additions and 0 deletions
@@ -532,6 +532,8 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
} else {
this._element.nativeElement.value = inputValue;
}
this._previousValue = inputValue;
}
/**
+27
View File
@@ -2194,6 +2194,33 @@ describe('MatAutocomplete', () => {
expect(Math.floor(overlayRect.top)).toBe(Math.floor(originRect.bottom),
'Expected autocomplete panel to align with the bottom of the new origin.');
});
it('should be able to re-type the same value when it is reset while open', fakeAsync(() => {
const fixture = createComponent(SimpleAutocomplete);
fixture.detectChanges();
const input = fixture.debugElement.query(By.css('input')).nativeElement;
const formControl = fixture.componentInstance.stateCtrl;
typeInElement('Cal', input);
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(formControl.value).toBe('Cal', 'Expected initial value to be propagated to model');
formControl.setValue('');
fixture.detectChanges();
expect(input.value).toBe('', 'Expected input value to reset when model is reset');
typeInElement('Cal', input);
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(formControl.value).toBe('Cal', 'Expected new value to be propagated to model');
}));
});
@Component({