From 95e382fc6273017c4739bf4e3a9603d720f3c253 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Thu, 7 Apr 2022 15:12:25 +0300 Subject: [PATCH] Search input: search on enter --- .../search-input/search-input.component.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sharedComponents/search-input/search-input.component.ts b/sharedComponents/search-input/search-input.component.ts index 3703f89e..1327cc2e 100644 --- a/sharedComponents/search-input/search-input.component.ts +++ b/sharedComponents/search-input/search-input.component.ts @@ -53,6 +53,16 @@ export class SearchInputComponent implements OnInit { constructor(private cdr: ChangeDetectorRef) { } + @HostListener('window:keydown', ['$event']) + keyEvent(event: KeyboardEvent) { + if(this.input.focused) { + if(event.code === 'Enter') { + event.preventDefault(); + this.search(event); + } + } + } + @HostListener('document:click', ['$event']) click(event) { if(event.isTrusted && this.expandable && !this.disabled) { @@ -72,7 +82,7 @@ export class SearchInputComponent implements OnInit { } } - public search(event) { + public search(event) { if(!this.disabled) { if (this.expandable) { this.expand(!this.expanded);