diff --git a/src/lib/autocomplete/autocomplete-trigger.ts b/src/lib/autocomplete/autocomplete-trigger.ts index 25fa1ee9a186..22dd34265699 100644 --- a/src/lib/autocomplete/autocomplete-trigger.ts +++ b/src/lib/autocomplete/autocomplete-trigger.ts @@ -205,6 +205,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy { _handleKeydown(event: KeyboardEvent): void { if (this.activeOption && event.keyCode === ENTER) { this.activeOption._selectViaInteraction(); + event.preventDefault(); } else { this.autocomplete._keyManager.onKeydown(event); if (event.keyCode === UP_ARROW || event.keyCode === DOWN_ARROW) { diff --git a/src/lib/autocomplete/autocomplete.spec.ts b/src/lib/autocomplete/autocomplete.spec.ts index 0c8b636f6040..f7ca92a28b8a 100644 --- a/src/lib/autocomplete/autocomplete.spec.ts +++ b/src/lib/autocomplete/autocomplete.spec.ts @@ -631,6 +631,20 @@ describe('MdAutocomplete', () => { }); })); + it('should prevent the default enter key action', async(() => { + fixture.whenStable().then(() => { + fixture.componentInstance.trigger._handleKeydown(DOWN_ARROW_EVENT); + + fixture.whenStable().then(() => { + spyOn(ENTER_EVENT, 'preventDefault'); + + fixture.componentInstance.trigger._handleKeydown(ENTER_EVENT); + + expect(ENTER_EVENT.preventDefault).toHaveBeenCalled(); + }); + }); + })); + it('should fill the text field, not select an option, when SPACE is entered', async(() => { fixture.whenStable().then(() => { typeInElement('New', input);