mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(autocomplete): not propagating same model value when reset while open (#13634)
This commit is contained in:
committed by
Joey Perrott
parent
fa6e46da98
commit
8d98375237
@@ -532,6 +532,8 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
|
||||
} else {
|
||||
this._element.nativeElement.value = inputValue;
|
||||
}
|
||||
|
||||
this._previousValue = inputValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user