File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -224,15 +224,21 @@ export default function AppLayout() {
224224
225225 if ( globalSearchOpen && globalSearchResults . length > 0 && event . key === "ArrowDown" ) {
226226 event . preventDefault ( ) ;
227- setGlobalSearchSelectedIndex ( ( prev , ) => ( prev + 1 ) % globalSearchResults . length ) ;
227+ setGlobalSearchSelectedIndex ( ( prev , ) => {
228+ const lastIndex = globalSearchResults . length - 1 ;
229+ if ( prev < 0 ) return 0 ;
230+ if ( prev >= lastIndex ) return lastIndex ;
231+ return prev + 1 ;
232+ } , ) ;
228233 return ;
229234 }
230235
231236 if ( globalSearchOpen && globalSearchResults . length > 0 && event . key === "ArrowUp" ) {
232237 event . preventDefault ( ) ;
233- setGlobalSearchSelectedIndex ( ( prev , ) => (
234- prev <= 0 ? globalSearchResults . length - 1 : prev - 1
235- ) ) ;
238+ setGlobalSearchSelectedIndex ( ( prev , ) => {
239+ if ( prev <= 0 ) return 0 ;
240+ return prev - 1 ;
241+ } , ) ;
236242 return ;
237243 }
238244
You can’t perform that action at this time.
0 commit comments