Skip to content

Commit 8518079

Browse files
fix(client):make menu bar disappear after user chooses item from it on landing page (freeCodeCamp#43458)
* removed serachBarRef * removed serachBarRef * Revert "removed serachBarRef" This reverts commit 6a5c2f4. * Revert "removed serachBarRef" This reverts commit 67710b3. * added innerRef as ref to SearchBarOptimized component * Update client/src/components/Header/index.tsx Co-authored-by: Oliver Eyton-Williams <[email protected]> * Update client/src/components/search/searchBar/search-bar-optimized.tsx Co-authored-by: Oliver Eyton-Williams <[email protected]> * Update client/src/components/search/searchBar/search-bar-optimized.tsx Co-authored-by: Oliver Eyton-Williams <[email protected]> Co-authored-by: Oliver Eyton-Williams <[email protected]>
1 parent bc802cb commit 8518079

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

client/src/components/Header/components/universal-nav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const UniversalNav = ({
3737

3838
const search =
3939
typeof window !== `undefined` && isLanding(window.location.pathname) ? (
40-
<SearchBarOptimized />
40+
<SearchBarOptimized innerRef={searchBarRef} />
4141
) : (
4242
<SearchBar innerRef={searchBarRef} />
4343
);

client/src/components/Header/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export class Header extends React.Component<
4444
this.state.displayMenu &&
4545
this.menuButtonRef.current &&
4646
!this.menuButtonRef.current.contains(event.target) &&
47+
// since the search bar is part of the menu on small screens, clicks on
48+
// the search bar should not toggle the menu
4749
this.searchBarRef.current &&
4850
!this.searchBarRef.current.contains(event.target)
4951
) {

client/src/components/search/searchBar/search-bar-optimized.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { useTranslation } from 'react-i18next';
33
import Magnifier from '../../../assets/icons/Magnifier';
44
import { searchPageUrl } from '../../../utils/algolia-locale-setup';
55

6-
const SearchBarOptimized = (): JSX.Element => {
6+
type Props = {
7+
innerRef?: React.RefObject<HTMLDivElement>;
8+
};
9+
10+
const SearchBarOptimized = ({ innerRef }: Props): JSX.Element => {
711
const { t } = useTranslation();
812
const placeholder = t('search.placeholder');
913
const searchUrl = searchPageUrl;
@@ -18,7 +22,7 @@ const SearchBarOptimized = (): JSX.Element => {
1822
};
1923

2024
return (
21-
<div className='fcc_searchBar' data-testid='fcc_searchBar'>
25+
<div className='fcc_searchBar' data-testid='fcc_searchBar' ref={innerRef}>
2226
<div className='fcc_search_wrapper'>
2327
<div className='ais-SearchBox' data-cy='ais-SearchBox'>
2428
<form

0 commit comments

Comments
 (0)