Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not allow search submit if no terms entered #446

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/src/components/Shared/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ const SearchBar: React.FC<SearchBarProps> = ({ handleSubmit }) => {
}
};
const handleSearchClick = () => {
if (selectedOptions?.length === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if selectedOptions could be undefined and that would then cause this to be false and submit the form anyways, but it looks like its always set to [] as far as I can tell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, its default is always [] if the state is never changed! as long as no one ever changes any of the setSelectedOptions([]) to something other than [], we should be in the clear! Another potential issue could be if event.target.value is ever undefined... I don't see how that could happen unless there was some sort of data issue with the search suggestions, though.

return;
}
state.searchTerms = selectedOptions.map((option) => option.suggestion);
handleSubmit();
};
Expand Down