From 2f4a5e03264819613ce3bf61c46e93b664576211 Mon Sep 17 00:00:00 2001 From: Tomasz Zielinski Date: Wed, 19 Apr 2017 19:08:08 +0100 Subject: [PATCH 1/2] Fixes 1559, does not show list on focus when minLenth is 0. --- src/typeahead/typeahead.directive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typeahead/typeahead.directive.ts b/src/typeahead/typeahead.directive.ts index 4e0c61144e..c97e4c4d3d 100644 --- a/src/typeahead/typeahead.directive.ts +++ b/src/typeahead/typeahead.directive.ts @@ -134,7 +134,7 @@ export class TypeaheadDirective implements OnInit, OnDestroy { @HostListener('focus') public onFocus(): void { - if (this.typeaheadMinLength === 0) { + if (this.typeaheadMinLength == 0) { this.typeaheadLoading.emit(true); this.keyUpEventEmitter.emit(''); } From 6fe09dfc2c6cd2871d7421d3c507d792590420a8 Mon Sep 17 00:00:00 2001 From: Tomasz Zielinski Date: Wed, 19 Apr 2017 21:05:22 +0100 Subject: [PATCH 2/2] Fixes 1559, added tests for onFocus. --- src/spec/typeahead.directive.spec.ts | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/spec/typeahead.directive.spec.ts b/src/spec/typeahead.directive.spec.ts index 67383dabca..bd8b893f8f 100644 --- a/src/spec/typeahead.directive.spec.ts +++ b/src/spec/typeahead.directive.spec.ts @@ -186,5 +186,58 @@ describe('Directive: Typeahead', () => { fixture.detectChanges(); }); }); + + describe('onFocus', () => { + beforeEach(fakeAsync(() => { + + })); + + it('should result in a total of 2 matches, when minLength === 0', fakeAsync(() => { + expect(directive).toBeDefined(); + + directive.typeaheadMinLength = 0; + fixture.detectChanges(); + tick(100); + + expect(directive.typeaheadMinLength).toBe(0); + directive.onFocus(); + + tick(100); + + expect(directive.matches.length).toBe(2); + })); + + it('should result in a total of 2 matches, when minLength === \"0\"', fakeAsync(() => { + expect(directive).toBeDefined(); + + directive.typeaheadMinLength = '0'; + fixture.detectChanges(); + tick(100); + + expect(directive.typeaheadMinLength).toBe('0'); + directive.onFocus(); + + tick(100); + + expect(directive.matches.length).toBe(2); + })); + + it('should do nothing, when minLength > 0', fakeAsync(() => { + expect(directive).toBeDefined(); + + directive.typeaheadMinLength = 1; + fixture.detectChanges(); + tick(100); + + expect(directive.typeaheadMinLength).toBe(1); + directive.onFocus(); + + tick(100); + + expect(directive.matches).toBeUndefined(); + })); + + + }); });