Skip to content

Commit 2006144

Browse files
crisbetojosephperrott
authored andcommitted
fix(autocomplete): not propagating same model value when reset while open (#13634)
1 parent 85a3ae0 commit 2006144

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,8 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
532532
} else {
533533
this._element.nativeElement.value = inputValue;
534534
}
535+
536+
this._previousValue = inputValue;
535537
}
536538

537539
/**

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,33 @@ describe('MatAutocomplete', () => {
21942194
expect(Math.floor(overlayRect.top)).toBe(Math.floor(originRect.bottom),
21952195
'Expected autocomplete panel to align with the bottom of the new origin.');
21962196
});
2197+
2198+
it('should be able to re-type the same value when it is reset while open', fakeAsync(() => {
2199+
const fixture = createComponent(SimpleAutocomplete);
2200+
fixture.detectChanges();
2201+
const input = fixture.debugElement.query(By.css('input')).nativeElement;
2202+
const formControl = fixture.componentInstance.stateCtrl;
2203+
2204+
typeInElement('Cal', input);
2205+
fixture.detectChanges();
2206+
tick();
2207+
fixture.detectChanges();
2208+
2209+
expect(formControl.value).toBe('Cal', 'Expected initial value to be propagated to model');
2210+
2211+
formControl.setValue('');
2212+
fixture.detectChanges();
2213+
2214+
expect(input.value).toBe('', 'Expected input value to reset when model is reset');
2215+
2216+
typeInElement('Cal', input);
2217+
fixture.detectChanges();
2218+
tick();
2219+
fixture.detectChanges();
2220+
2221+
expect(formControl.value).toBe('Cal', 'Expected new value to be propagated to model');
2222+
}));
2223+
21972224
});
21982225

21992226
@Component({

0 commit comments

Comments
 (0)