@@ -471,8 +471,11 @@ export function SearchOverlay({
471
471
selectedIndex < combinedOptions . length
472
472
) {
473
473
const selectedItem = combinedOptions [ selectedIndex ]
474
+ if ( ! selectedItem ) {
475
+ return
476
+ }
474
477
let action = ( ) => { } // Execute the action after we send the event
475
- if ( selectedItem . group === 'general' ) {
478
+ if ( selectedItem ? .group === 'general' ) {
476
479
if (
477
480
( selectedItem . option as GeneralSearchHitWithOptions ) . isViewAllResults ||
478
481
( selectedItem . option as GeneralSearchHitWithOptions ) . isSearchDocsOption
@@ -483,10 +486,10 @@ export function SearchOverlay({
483
486
pressedOnContext = 'general-option'
484
487
action = ( ) => generalSearchResultOnSelect ( selectedItem . option as GeneralSearchHit )
485
488
}
486
- } else if ( selectedItem . group === 'ai' ) {
489
+ } else if ( selectedItem ? .group === 'ai' ) {
487
490
pressedOnContext = 'ai-option'
488
491
action = ( ) => aiSearchOptionOnSelect ( selectedItem . option as AutocompleteSearchHit )
489
- } else if ( selectedItem . group === 'reference' ) {
492
+ } else if ( selectedItem ? .group === 'reference' ) {
490
493
// On a reference select, we are in the Ask AI State / Screen
491
494
pressedGroupKey = ASK_AI_EVENT_GROUP
492
495
pressedGroupId = askAIEventGroupId
@@ -509,6 +512,8 @@ export function SearchOverlay({
509
512
'search-overlay-ask-ai' : '' ,
510
513
'search-overlay-input' : urlSearchInputQuery ,
511
514
} )
515
+ // Focus the search input
516
+ inputRef . current ?. focus ( )
512
517
}
513
518
514
519
// We render the AI Result in the searchGroups call, so we pass the props down via an object
@@ -681,7 +686,7 @@ export function SearchOverlay({
681
686
aria-expanded = { combinedOptions . length > 0 }
682
687
aria-activedescendant = {
683
688
selectedIndex >= 0
684
- ? `search-option-${ combinedOptions [ selectedIndex ] . group } -${ selectedIndex } `
689
+ ? `search-option-${ combinedOptions [ selectedIndex ] ? .group } -${ selectedIndex } `
685
690
: undefined
686
691
}
687
692
onKeyDown = { handleKeyDown }
0 commit comments