Skip to content

Commit

Permalink
feat(typeahead): add more on blur logic (#5629)
Browse files Browse the repository at this point in the history
Co-authored-by: dmitry-zhemchugov <44227371+dmitry-zhemchugov@users.noreply.github.com>
  • Loading branch information
daniloff200 and dmitry-zhemchugov authored Feb 26, 2020
1 parent 23800f5 commit c4f5236
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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();
Expand Down

0 comments on commit c4f5236

Please sign in to comment.