Skip to content

Commit 4c624e4

Browse files
authored
fix keyboard related copilot search bugs (#55297)
1 parent 506d3aa commit 4c624e4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/search/components/input/SearchOverlay.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,11 @@ export function SearchOverlay({
471471
selectedIndex < combinedOptions.length
472472
) {
473473
const selectedItem = combinedOptions[selectedIndex]
474+
if (!selectedItem) {
475+
return
476+
}
474477
let action = () => {} // Execute the action after we send the event
475-
if (selectedItem.group === 'general') {
478+
if (selectedItem?.group === 'general') {
476479
if (
477480
(selectedItem.option as GeneralSearchHitWithOptions).isViewAllResults ||
478481
(selectedItem.option as GeneralSearchHitWithOptions).isSearchDocsOption
@@ -483,10 +486,10 @@ export function SearchOverlay({
483486
pressedOnContext = 'general-option'
484487
action = () => generalSearchResultOnSelect(selectedItem.option as GeneralSearchHit)
485488
}
486-
} else if (selectedItem.group === 'ai') {
489+
} else if (selectedItem?.group === 'ai') {
487490
pressedOnContext = 'ai-option'
488491
action = () => aiSearchOptionOnSelect(selectedItem.option as AutocompleteSearchHit)
489-
} else if (selectedItem.group === 'reference') {
492+
} else if (selectedItem?.group === 'reference') {
490493
// On a reference select, we are in the Ask AI State / Screen
491494
pressedGroupKey = ASK_AI_EVENT_GROUP
492495
pressedGroupId = askAIEventGroupId
@@ -509,6 +512,8 @@ export function SearchOverlay({
509512
'search-overlay-ask-ai': '',
510513
'search-overlay-input': urlSearchInputQuery,
511514
})
515+
// Focus the search input
516+
inputRef.current?.focus()
512517
}
513518

514519
// 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({
681686
aria-expanded={combinedOptions.length > 0}
682687
aria-activedescendant={
683688
selectedIndex >= 0
684-
? `search-option-${combinedOptions[selectedIndex].group}-${selectedIndex}`
689+
? `search-option-${combinedOptions[selectedIndex]?.group}-${selectedIndex}`
685690
: undefined
686691
}
687692
onKeyDown={handleKeyDown}

0 commit comments

Comments
 (0)