Skip to content

Commit

Permalink
Merge branch 'searchbox-click-hide' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramin Farhadi authored and Ramin Farhadi committed Aug 21, 2024
2 parents 8b07d89 + 1ec9d5d commit d0c9df9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface SearchResultsProps {
export default function SearchResults(props: SearchResultsProps) {
const [searchQuery, setSearchQuery] = useState<string>('');
const [debouncedSearchQuery, setDebouncedSearchQuery] = useState<string>('');
const [searchBoxVisibility,setSearchBoxVisibility] = useState<boolean>(false);

useEffect(() => {
const delaySearchQueryTimeOutId = setTimeout(() => {
Expand Down Expand Up @@ -53,8 +54,9 @@ export default function SearchResults(props: SearchResultsProps) {
aria-label='Search for locations,services, parking, and more'
value={searchQuery}
onChange={(e) => {
!searchBoxVisibility && e.target.value ? setSearchBoxVisibility(true) : ''
setSearchQuery(e.target.value);
props.searchData(e.target.value)
props.searchData(e.target.value);
}}
tabIndex={0}
role='searchbox'
Expand All @@ -63,11 +65,13 @@ export default function SearchResults(props: SearchResultsProps) {
{
searchQuery !== '' ? (
<img width={20} src={closeIcon} onClick={() => {
searchBoxVisibility ? setSearchBoxVisibility (false) : ''
props.searchData(null)
setSearchQuery('');
}}
onKeyDown={(e)=>{
if(e.key === 'Enter'){
searchBoxVisibility ? setSearchBoxVisibility (false) : ''
props.searchData(null)
setSearchQuery('');
}
Expand All @@ -81,7 +85,7 @@ export default function SearchResults(props: SearchResultsProps) {
) }
</div>
</div>
{props.searchResults && props.searchResults.length > 0 && (
{props.searchResults && props.searchResults.length > 0 && searchBoxVisibility && (
<div className='search-results-container'>
<h2 className='sr-only'>Search Results</h2>
<ul role="listbox" tabIndex={-1} id='search-results' className='search-results'>
Expand All @@ -90,9 +94,14 @@ export default function SearchResults(props: SearchResultsProps) {
<li key={result!.properties!.Name} className='list-item search-result'>
<a
className='search-result-link'
onClick={() => props.onSearchResultClick(result)}
onClick={() => {
setSearchBoxVisibility(false);
props.onSearchResultClick(result);
}
}
onKeyDown={(e) => {
if (e.key === 'Enter') {
setSearchBoxVisibility(false);
props.onSearchResultClick(result);
}
}}
Expand Down

0 comments on commit d0c9df9

Please sign in to comment.