Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit e821ae3

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(autocomplete): don't show the loading bar when hitting escape on an empty input
The loading bar was being shown if the user pressed escape on an empty autocomplete input. Closes #7927. Closes #7934
1 parent f687d10 commit e821ae3

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/components/autocomplete/autocomplete.spec.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('<md-autocomplete>', function() {
102102

103103
element.remove();
104104
}));
105-
105+
106106

107107
it('should allow you to set an input id without floating label', inject(function() {
108108
var scope = createScope(null, {inputId: 'custom-input-id'});
@@ -321,6 +321,26 @@ describe('<md-autocomplete>', function() {
321321
element.remove();
322322
}));
323323

324+
it('should not show the progressbar when hitting escape on an empty input', inject(function($mdConstant, $timeout) {
325+
var scope = createScope();
326+
var template = '\
327+
<md-autocomplete\
328+
md-search-text="searchText"\
329+
md-items="item in match(searchText)">\
330+
</md-autocomplete>';
331+
var element = compile(template, scope);
332+
var ctrl = element.controller('mdAutocomplete');
333+
334+
$timeout.flush();
335+
scope.$apply(function() {
336+
ctrl.keydown(keydownEvent($mdConstant.KEY_CODE.ESCAPE));
337+
});
338+
339+
expect(element.find('md-progress-linear').length).toBe(0);
340+
341+
element.remove();
342+
}));
343+
324344
it('should not close list on ENTER key if nothing is selected', inject(function($timeout, $mdConstant, $material) {
325345
var scope = createScope();
326346
var template = '\

src/components/autocomplete/js/autocompleteController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
443443
case $mdConstant.KEY_CODE.ESCAPE:
444444
event.stopPropagation();
445445
event.preventDefault();
446-
clearValue();
446+
if ($scope.searchText) clearValue();
447447

448448
// Force the component to blur if they hit escape
449449
doBlur(true);

0 commit comments

Comments
 (0)