From c4f52369b3d84b9855b0928543ff4625153c43ff Mon Sep 17 00:00:00 2001 From: Dmitriy Danilov Date: Wed, 26 Feb 2020 16:57:50 +0200 Subject: [PATCH] feat(typeahead): add more on blur logic (#5629) Co-authored-by: dmitry-zhemchugov <44227371+dmitry-zhemchugov@users.noreply.github.com> --- src/typeahead/typeahead.directive.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/typeahead/typeahead.directive.ts b/src/typeahead/typeahead.directive.ts index 981e26a17b..884f63d561 100644 --- a/src/typeahead/typeahead.directive.ts +++ b/src/typeahead/typeahead.directive.ts @@ -290,6 +290,13 @@ export class TypeaheadDirective implements OnInit, OnDestroy { if (this._container && !this._container.isFocused) { this.typeaheadOnBlur.emit(this._container.active); } + + if (!this.container && this._matches.length === 0) { + this.typeaheadOnBlur.emit(new TypeaheadMatch( + this.element.nativeElement.value, + this.element.nativeElement.value, + false)); + } } @HostListener('keydown', ['$event']) @@ -299,6 +306,11 @@ export class TypeaheadDirective implements OnInit, OnDestroy { return; } + /* tslint:disable-next-line: deprecation */ + if (event.keyCode === 9 || event.key === 'Tab') { + this.onBlur(); + } + /* tslint:disable-next-line: deprecation */ if (event.keyCode === 9 || event.key === 'Tab' || event.keyCode === 13 || event.key === 'Enter') { event.preventDefault();