Skip to content
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

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

Merged
merged 1 commit into from Jul 10, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/autocomplete/autocomplete-trigger.ts
Expand Up @@ -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;

Expand Down
17 changes: 16 additions & 1 deletion src/lib/autocomplete/autocomplete.spec.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -2464,7 +2474,6 @@ class AutocompleteWithDifferentOrigin {
values = ['one', 'two', 'three'];
}


@Component({
template: `
<input autocomplete="changed" [(ngModel)]="value" [matAutocomplete]="auto"/>
Expand All @@ -2474,3 +2483,9 @@ class AutocompleteWithDifferentOrigin {
class AutocompleteWithNativeAutocompleteAttribute {
value: string;
}

@Component({
template: '<input [matAutocomplete]="null" matAutocompleteDisabled>'
})
class InputWithoutAutocompleteAndDisabled {
}