Skip to content

fix(autocomplete): model not being updated when typing in input with disabled autocomplete #11695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,13 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
// filter out all of the extra events, we save the value on focus and between
// `input` events, and we check whether it changed.
// See: https://connect.microsoft.com/IE/feedback/details/885747/
if (this._canOpen() && this._previousValue !== value &&
document.activeElement === event.target) {
if (this._previousValue !== value && document.activeElement === event.target) {
this._previousValue = value;
this._onChange(value);
this.openPanel();

if (this._canOpen()) {
this.openPanel();
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,16 @@ describe('MatAutocomplete', () => {
.toBe(false, `Expected panel to remain closed.`);
});

it('should continue to update the model if the autocomplete is disabled', () => {
fixture.componentInstance.autocompleteDisabled = true;
fixture.detectChanges();

typeInElement('hello', input);
fixture.detectChanges();

expect(fixture.componentInstance.stateCtrl.value).toBe('hello');
});

});

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