From 937e49fbf16c75365224e7cd8a92472d9f7db738 Mon Sep 17 00:00:00 2001 From: Chenyu Zhang Date: Fri, 30 Oct 2015 11:27:29 -0400 Subject: [PATCH] feat(typeahead): display all items when focus with min-length=0 --- src/typeahead/test/typeahead.spec.js | 8 ++++++++ src/typeahead/typeahead.js | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 55d34a1568..547a44b5be 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -1204,6 +1204,14 @@ describe('typeahead tests', function() { changeInputValueTo(element, ''); expect(element).toBeOpenWithActive(3, 0); }); + + it('should open typeahead when input is focused and value is empty if defined threshold is 0', function () { + var element = prepareInputEl('
'); + var inputEl = findInput(element); + inputEl.focus(); + $scope.$digest(); + expect(element).toBeOpenWithActive(3, 0); + }); }); describe('event listeners', function() { diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index e94635858d..1ed9cedd54 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -385,6 +385,13 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position']) } }); + element.bind('focus', function () { + hasFocus = true; + if (minLength === 0 && !modelCtrl.$viewValue) { + getMatchesAsync(modelCtrl.$viewValue); + } + }); + element.bind('blur', function() { if (isSelectOnBlur && scope.matches.length && scope.activeIdx !== -1 && !selected) { selected = true; @@ -393,7 +400,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position']) }); } if (!isEditable && modelCtrl.$error.editable) { - element.val(''); + modelCtrl.$viewValue = ''; + element.val(''); } hasFocus = false; selected = false;