Skip to content

Commit

Permalink
feat: clear search results when search field is cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
aethant committed Oct 31, 2023
1 parent ce24a58 commit 66f01d3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/course-home/courseware-search/CoursewareSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const CoursewareSearch = ({ intl, ...sectionProps }) => {
setResults(search.toLowerCase() !== 'lorem ipsum' ? mockedData : []);
};

const handleChange = (value) => {
if (!value?.length) { setResults(undefined); }
};

return (
<section className="courseware-search" style={{ '--modal-top-position': top }} data-testid="courseware-search-section" {...sectionProps}>
<div className="courseware-search__close">
Expand All @@ -48,6 +52,7 @@ const CoursewareSearch = ({ intl, ...sectionProps }) => {
<h2>{intl.formatMessage(messages.searchModuleTitle)}</h2>
<CoursewareSearchForm
onSubmit={handleSubmit}
onChange={handleChange}
placeholder={intl.formatMessage(messages.searchBarPlaceholderText)}
/>
<CoursewareSearchResultsFilterContainer results={results} />
Expand Down

0 comments on commit 66f01d3

Please sign in to comment.