Skip to content

Commit bb6bcdb

Browse files
committed
add: Enter key navigation for quick search
Press Enter in the quick search input to navigate directly to the first search result.
1 parent 6cdbcfb commit bb6bcdb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

resources/views/partials/quick-search-dropdown.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class="quick-search__input"
99
x-ref="quickSearch"
1010
x-on:keydown.down.prevent="focusFirstResult"
1111
x-on:keydown.up.prevent="focusLastResult"
12+
x-on:keydown.enter="navigateToFirstResult"
1213
x-on:focus="searchPerformed = true"
1314
/>
1415
<template x-if="searchResults === null">
@@ -90,6 +91,11 @@ class="quick-search__result-type"
9091
this.searchResults = [];
9192
this.searchPerformed = false;
9293
},
94+
navigateToFirstResult() {
95+
if (Array.isArray(this.searchResults) && this.searchResults.length > 0) {
96+
window.location.href = this.searchResults[0].url;
97+
}
98+
},
9399
focusFirstResult() {
94100
document.querySelector('[x-ref="searchResults"]').querySelector('a').focus();
95101
},

0 commit comments

Comments
 (0)