diff --git a/packages/cli/src/components/SearchBox.tsx b/packages/cli/src/components/SearchBox.tsx index c0a64ed..15d50ab 100644 --- a/packages/cli/src/components/SearchBox.tsx +++ b/packages/cli/src/components/SearchBox.tsx @@ -20,29 +20,36 @@ export function SearchBox({ onSubmit?: (value: string) => void }) { const [query, setQuery] = useState(initialQuery ?? '') + const [queryMode, setQueryMode] = useState(true) const [isLoading, setLoading] = useState(false) const [suggestions, setSuggestions] = useState([]) const [selected, setSelected] = useState(0) useEffect(() => { - setLoading(true) - getSuggestion( - components.map(({key}) => key), - query, - ).then((result) => { - setSuggestions(result) - setLoading(false) - if (result.length <= selected) { - setSelected(result.length - 1) - } - }) - }, [query]) + if (queryMode) { + setLoading(true) + getSuggestion( + components.map(({key}) => key), + query, + ).then((result) => { + setSuggestions(result) + setLoading(false) + if (result.length <= selected) { + setSelected(result.length - 1) + } + }) + } + }, [query, queryMode]) useEffect(() => { if (onChange) { const found = components.find(({key}) => key === suggestions[selected]) found && onChange(found) } + if (suggestions[selected]) { + setQueryMode(false) + setQuery(suggestions[selected] ?? '') + } }, [selected, onChange]) const app = useApp() @@ -64,7 +71,16 @@ export function SearchBox({ Search? - setQuery(v)} showCursor placeholder={' query'} onSubmit={onSubmit} /> + { + setQueryMode(true) + setQuery(v) + }} + showCursor + placeholder={' query'} + onSubmit={onSubmit} + />