Skip to content

Commit

Permalink
fix(typeahead): fix error on blur after init
Browse files Browse the repository at this point in the history
Fix error thrown on blur before input is given

Closes valor-software#5736
  • Loading branch information
Michael Hobbs committed Apr 12, 2020
1 parent f6240fa commit 1077f54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/spec/typeahead.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ describe('Directive: Typeahead', () => {
expect(fixture.debugElement.query(By.css('typeahead-container'))).toBeNull();
})
);

it('should not throw an error on blur', fakeAsync(() => {
expect(directive._container).toBeFalsy();
expect(directive.matches).toEqual([]);

dispatchMouseEvent(inputElement, 'click');
tick();
fixture.detectChanges();

fixture.whenStable().then(() => {
expect(() => directive.onBlur()).not.toThrowError();
});
}));
});

describe('onFocus', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class TypeaheadDirective implements OnInit, OnDestroy {

// tslint:disable-next-line:no-any
protected keyUpEventEmitter: EventEmitter<string> = new EventEmitter();
protected _matches: TypeaheadMatch[];
protected _matches: TypeaheadMatch[] = [];
protected placement = 'bottom left';

private _typeahead: ComponentLoader<TypeaheadContainerComponent>;
Expand Down

0 comments on commit 1077f54

Please sign in to comment.