Skip to content

Commit 3f8711f

Browse files
crisbetovictoriaaa234
authored andcommitted
fix(autocomplete): model not being updated when typing in input with disabled autocomplete (#11695)
Fixes the model of an input with `matAutocompleteDisabled=true` not being updated while typing. Fixes #11678.
1 parent b03b69c commit 3f8711f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,13 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
358358
// filter out all of the extra events, we save the value on focus and between
359359
// `input` events, and we check whether it changed.
360360
// See: https://connect.microsoft.com/IE/feedback/details/885747/
361-
if (this._canOpen() && this._previousValue !== value &&
362-
document.activeElement === event.target) {
361+
if (this._previousValue !== value && document.activeElement === event.target) {
363362
this._previousValue = value;
364363
this._onChange(value);
365-
this.openPanel();
364+
365+
if (this._canOpen()) {
366+
this.openPanel();
367+
}
366368
}
367369
}
368370

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,16 @@ describe('MatAutocomplete', () => {
470470
.toBe(false, `Expected panel to remain closed.`);
471471
});
472472

473+
it('should continue to update the model if the autocomplete is disabled', () => {
474+
fixture.componentInstance.autocompleteDisabled = true;
475+
fixture.detectChanges();
476+
477+
typeInElement('hello', input);
478+
fixture.detectChanges();
479+
480+
expect(fixture.componentInstance.stateCtrl.value).toBe('hello');
481+
});
482+
473483
});
474484

475485
it('should have the correct text direction in RTL', () => {

0 commit comments

Comments
 (0)