I still have to double click the suggested searches before redirecting it to its link. Recently I've added the tabindex
for the hide()
and show()
methods to work
Here are my code:
getSuggestion(name) {
$('.suggestion').show();
this.search
.getSuggestion(name)
.subscribe(
name => this.results = name,
error => alert(error),
);
}
hide($event) {
this.suggest = false;
}
show($event) {
this.suggest = true;
}
showEmployee(id: string) {
this.route.navigate(['/information/employees', id]);
this.results = [];
}
<section class="search-bar-wrapper" tabindex="-1" (focusin)="show($event)" (focusout)="hide($event)">
<div class="ui right action left icon input fullwidth" >
<input type="text" placeholder="Search" (keyup)="getSuggestion($event.target.value)">
<div class="suggestion" *ngIf="results.length > 0 && suggest === true">
<div *ngFor="let result of results">
<div class="search-res" (click)="showEmployee(result._id)"> {{ result.name }} </div>
</div>
</div>
</div>
</section>