diff --git a/web/src/components/ChatInput/Autocomplete.tsx b/web/src/components/ChatInput/Autocomplete.tsx index eb226464..8acb517b 100644 --- a/web/src/components/ChatInput/Autocomplete.tsx +++ b/web/src/components/ChatInput/Autocomplete.tsx @@ -1,4 +1,4 @@ -import { memo } from 'react' +import { memo, useEffect, useRef } from 'react' import type { Suggestion } from '@/hooks/useActiveSuggestions' interface AutocompleteProps { @@ -12,17 +12,29 @@ interface AutocompleteProps { */ export const Autocomplete = memo(function Autocomplete(props: AutocompleteProps) { const { suggestions, selectedIndex, onSelect } = props + const listRef = useRef(null) + + useEffect(() => { + if (selectedIndex < 0 || selectedIndex >= suggestions.length) return + const listEl = listRef.current + if (!listEl) return + const selectedEl = listEl.querySelector( + `[data-suggestion-index="${selectedIndex}"]` + ) + selectedEl?.scrollIntoView({ block: 'nearest' }) + }, [selectedIndex, suggestions]) if (suggestions.length === 0) { return null } return ( -
+
{suggestions.map((suggestion, index) => (