Auto-close menu when single item chosen with Enter key

This commit is contained in:
Michael Shamoon 2020-12-13 15:47:46 -08:00
parent ee7492cf52
commit 245af65841
2 changed files with 3 additions and 1 deletions

View File

@ -1,4 +1,4 @@
<div class="btn-group" ngbDropdown role="group" (openChange)="dropdownOpenChange($event)">
<div class="btn-group" ngbDropdown role="group" (openChange)="dropdownOpenChange($event)" #filterDropdown="ngbDropdown">
<button class="btn btn-outline-primary btn-sm" id="dropdown{{title}}" ngbDropdownToggle>
<ng-container *ngIf="itemsSelected?.length > 0">
<div class="badge bg-secondary text-light rounded-pill ml-auto">

View File

@ -29,6 +29,7 @@ export class FilterDropdownComponent {
toggle = new EventEmitter()
@ViewChild('listFilterTextInput') listFilterTextInput: ElementRef
@ViewChild('filterDropdown') filterDropdown: NgbDropdown
filterText: string
@ -53,5 +54,6 @@ export class FilterDropdownComponent {
listFilterEnter(): void {
let filtered = this.filterPipe.transform(this.items, this.filterText)
if (filtered.length == 1) this.toggleItem(filtered.shift())
this.filterDropdown.close()
}
}