diff --git a/src/components/autocomplete/autocomplete.spec.js b/src/components/autocomplete/autocomplete.spec.js index 9b3a41e6c3b..af5d9ff7133 100644 --- a/src/components/autocomplete/autocomplete.spec.js +++ b/src/components/autocomplete/autocomplete.spec.js @@ -102,7 +102,7 @@ describe('', function() { element.remove(); })); - + it('should allow you to set an input id without floating label', inject(function() { var scope = createScope(null, {inputId: 'custom-input-id'}); @@ -321,6 +321,26 @@ describe('', function() { element.remove(); })); + it('should not show the progressbar when hitting escape on an empty input', inject(function($mdConstant, $timeout) { + var scope = createScope(); + var template = '\ + \ + '; + var element = compile(template, scope); + var ctrl = element.controller('mdAutocomplete'); + + $timeout.flush(); + scope.$apply(function() { + ctrl.keydown(keydownEvent($mdConstant.KEY_CODE.ESCAPE)); + }); + + expect(element.find('md-progress-linear').length).toBe(0); + + element.remove(); + })); + it('should not close list on ENTER key if nothing is selected', inject(function($timeout, $mdConstant, $material) { var scope = createScope(); var template = '\ diff --git a/src/components/autocomplete/js/autocompleteController.js b/src/components/autocomplete/js/autocompleteController.js index ab23dbc9147..b897196189b 100644 --- a/src/components/autocomplete/js/autocompleteController.js +++ b/src/components/autocomplete/js/autocompleteController.js @@ -443,7 +443,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming, case $mdConstant.KEY_CODE.ESCAPE: event.stopPropagation(); event.preventDefault(); - clearValue(); + if ($scope.searchText) clearValue(); // Force the component to blur if they hit escape doBlur(true);