I have a single-selection Typeahead in my React app, and I'm trying to maintain the user's search input text after they select an option from the dropdown. Currently there may be multiple suggested results from their search input, but selecting one auto-updates the search input to this selection, eliminating the display of alternative options.
My original strategy was to store the search query string in a useState hook and update the Typeahead input with the old value as part of handleSelection, but that doesn't seem possible based on this answer.
const [searchQuery, setSearchQuery] = useState('');
const typeaheadRef = useRef(null);
const handleSelection = (selection:Object[]) => {
...do redux update on selection
typeaheadRef.current.value = searchQuery;
};
return(
<Typeahead
maxResults={50}
id="search-people"
options={filteredPeopleList}
labelKey={(option: Object) => option?.name ?? ''}
filterBy={['name']}
onChange={handleSelection}
ref={typeaheadRef}
onInputChange={query => setSearchQuery(query)}
/>)
Note: I am not passing a selected prop to the Typeahead.