From 1b6422bffeadf84ca634fa1368c2053b70ce190a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de>
Date: Tue, 3 Sep 2019 11:27:26 +0200
Subject: [PATCH] Check if search input field is empty

---
 .../shared/comment-list/comment-list.component.html    |  2 +-
 .../shared/comment-list/comment-list.component.ts      | 10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/app/components/shared/comment-list/comment-list.component.html b/src/app/components/shared/comment-list/comment-list.component.html
index 78e62eaf1..6b8093da3 100644
--- a/src/app/components/shared/comment-list/comment-list.component.html
+++ b/src/app/components/shared/comment-list/comment-list.component.html
@@ -18,7 +18,7 @@
     </div>
 
     <button mat-icon-button class="searchBarButton" (click)="activateSearch()"
-            *ngIf="deviceType === 'mobile' && !search && comments && comments.length > 0 && !search">
+            *ngIf="deviceType === 'mobile' && !search && comments && comments.length > 0">
       <mat-icon class="searchBarIcon">search</mat-icon>
     </button>
 
diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts
index e6c8b65ba..28770097e 100644
--- a/src/app/components/shared/comment-list/comment-list.component.ts
+++ b/src/app/components/shared/comment-list/comment-list.component.ts
@@ -114,9 +114,13 @@ export class CommentListComponent implements OnInit {
   }
 
   searchComments(): void {
-    if (this.searchInput && this.searchInput.length > 2) {
-      this.hideCommentsList = true;
-      this.filteredComments = this.comments.filter(c => c.body.toLowerCase().includes(this.searchInput.toLowerCase()));
+    if (this.searchInput) {
+      if (this.searchInput.length > 2) {
+        this.hideCommentsList = true;
+        this.filteredComments = this.comments.filter(c => c.body.toLowerCase().includes(this.searchInput.toLowerCase()));
+      }
+    } else {
+      this.hideCommentsList = false;
     }
   }
 
-- 
GitLab