circular keyboard navigation, fix with no results

This commit is contained in:
shamoon 2024-04-03 00:32:19 -07:00
parent 008c7868a6
commit 5d22fc76b4

View File

@ -73,15 +73,19 @@ export class GlobalSearchComponent {
) { ) {
if (event.key === 'ArrowDown') { if (event.key === 'ArrowDown') {
if (this.currentItemIndex < this.searchResults.total - 1) { if (this.currentItemIndex < this.searchResults.total - 1) {
event.preventDefault()
this.currentItemIndex++ this.currentItemIndex++
this.setCurrentItem() this.setCurrentItem()
} else {
event.preventDefault() event.preventDefault()
this.currentItemIndex = 0
this.setCurrentItem()
} }
} else if (event.key === 'ArrowUp') { } else if (event.key === 'ArrowUp') {
if (this.currentItemIndex > 0) { if (this.currentItemIndex > 0) {
event.preventDefault()
this.currentItemIndex-- this.currentItemIndex--
this.setCurrentItem() this.setCurrentItem()
event.preventDefault()
} else { } else {
this.searchInput.nativeElement.focus() this.searchInput.nativeElement.focus()
this.currentItemIndex = -1 this.currentItemIndex = -1
@ -267,9 +271,10 @@ export class GlobalSearchComponent {
public searchInputKeyDown(event: KeyboardEvent) { public searchInputKeyDown(event: KeyboardEvent) {
if ( if (
event.key === 'ArrowDown' && event.key === 'ArrowDown' &&
this.searchResults && this.searchResults?.total &&
this.resultsDropdown.isOpen() this.resultsDropdown.isOpen()
) { ) {
event.preventDefault()
this.currentItemIndex = 0 this.currentItemIndex = 0
this.setCurrentItem() this.setCurrentItem()
} else if ( } else if (