Skip to content

Commit

Permalink
allow empty-entering (clicking enter after selecting autocomplete ter…
Browse files Browse the repository at this point in the history
…ms by using space) by bringing back the handleKeyDown function for params.inputProps.onKeyDown in Autocomplete's renderInput (bringing it back from before #298)
  • Loading branch information
AbhiramTadepalli committed Jan 3, 2025
1 parent 24dbb30 commit 33909cf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/search/SearchBar/searchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ const SearchBar = ({
}
}

function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {
if (event.key === 'Enter' && inputValue === '') {
console.log('handleKeyDown');
event.preventDefault();
event.stopPropagation();
onSelect_internal(value);
}
}

useEffect(() => {
fetch('/api/autocomplete');
}, []);
Expand Down Expand Up @@ -241,6 +250,7 @@ const SearchBar = ({
loadNewOptions(newInputValue);
}}
renderInput={(params) => {
params.inputProps.onKeyDown = handleKeyDown;
return (
<TextField
{...params}
Expand All @@ -254,6 +264,7 @@ const SearchBar = ({
}}
//for handling spaces, when options are already loaded
onInput={(event) => {
console.log('onInput');
const value = (event.target as HTMLInputElement).value;
// if the last character in the new string is a space, check for autocomplete
if (
Expand Down

0 comments on commit 33909cf

Please sign in to comment.