Skip to content

Commit

Permalink
Update AutoComplete.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzy11 authored Jan 16, 2025
1 parent 0b09419 commit 3bc2591
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions frontend/src/components/common/AutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,27 @@ function AutoComplete(props) {

const onKeyDown = (e) => {
// Handeling enter key
const { onSelect } = props;
if (e.keyCode === 13) {
e.preventDefault();
if (filteredSuggestions[activeSuggestion]) {
const selectedValue = filteredSuggestions[activeSuggestion].value;
setTextValue(selectedValue); // Update local state
setUserInput(selectedValue);
setTextValue(selectedValue);
setShowSuggestions(false);
setInvalid(false);

if (typeof onSelect === "function") {
onSelect(filteredSuggestions[activeSuggestion].id);
}
}
}
}
// Handeling up arrow
else if (e.keyCode === 38) {
if (activeSuggestion === 0) {
return;
}
setActiveSuggestion(activeSuggestion - 1);
}
}
// Handeling down arrow
else if (e.keyCode === 40) {
if (activeSuggestion === filteredSuggestions.length - 1) {
Expand Down

0 comments on commit 3bc2591

Please sign in to comment.