fix(autocomplete): error when typing in input with disabled autocomplete and no panel (#11881)

Fixes an edge case where the input will throw an error if it has a disabled autocomplete and no autocomplete panel.

Fixes #11876.
This commit is contained in:
Kristiyan Kostadinov
2018-07-10 16:33:56 +02:00
committed by Jeremy Elbourn
parent ae39535644
commit 6b1a672c40
2 changed files with 17 additions and 2 deletions
+1 -1
View File
@@ -334,7 +334,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
this.activeOption._selectViaInteraction();
this._resetActiveItem();
event.preventDefault();
} else {
} else if (this.autocomplete) {
const prevActiveItem = this.autocomplete._keyManager.activeItem;
const isArrowKey = keyCode === UP_ARROW || keyCode === DOWN_ARROW;
+16 -1
View File
@@ -531,6 +531,16 @@ describe('MatAutocomplete', () => {
expect(input.getAttribute('autocomplete')).toBe('changed');
});
it('should not throw when typing in an element with a null and disabled autocomplete', () => {
const fixture = createComponent(InputWithoutAutocompleteAndDisabled);
fixture.detectChanges();
expect(() => {
dispatchKeyboardEvent(fixture.nativeElement.querySelector('input'), 'keydown', SPACE);
fixture.detectChanges();
}).not.toThrow();
});
describe('forms integration', () => {
let fixture: ComponentFixture<SimpleAutocomplete>;
let input: HTMLInputElement;
@@ -2464,7 +2474,6 @@ class AutocompleteWithDifferentOrigin {
values = ['one', 'two', 'three'];
}
@Component({
template: `
<input autocomplete="changed" [(ngModel)]="value" [matAutocomplete]="auto"/>
@@ -2474,3 +2483,9 @@ class AutocompleteWithDifferentOrigin {
class AutocompleteWithNativeAutocompleteAttribute {
value: string;
}
@Component({
template: '<input [matAutocomplete]="null" matAutocompleteDisabled>'
})
class InputWithoutAutocompleteAndDisabled {
}