From 956856e0e707349820f2b4d84c49b7969cac7ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Delattre?= Date: Mon, 22 Jul 2019 21:02:35 +0200 Subject: [PATCH] Close the navbar after a search --- frontend/js/components/navbar.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/js/components/navbar.js b/frontend/js/components/navbar.js index 56515c8..aa3c798 100644 --- a/frontend/js/components/navbar.js +++ b/frontend/js/components/navbar.js @@ -43,6 +43,7 @@ const AppNavBar = (props) => { placeholder="Search movies" path='/movies/search' history={props.history} + setExpanded={setExpanded} /> }/> @@ -50,6 +51,7 @@ const AppNavBar = (props) => { placeholder="Search shows" path='/shows/search' history={props.history} + setExpanded={setExpanded} /> }/> { +const Search = ({ path, placeholder, setExpanded, history }) => { const [search, setSearch] = useState(""); const handleSearch = (ev) => { ev.preventDefault(); - props.history.push(`${props.path}/${encodeURI(search)}`); + history.push(`${path}/${encodeURI(search)}`); + setExpanded(false); } return( @@ -83,7 +86,7 @@ const Search = (props) => {
handleSearch(ev)}> setSearch(e.target.value)} /> @@ -93,6 +96,7 @@ const Search = (props) => { } Search.propTypes = { placeholder: PropTypes.string.isRequired, + setExpanded: PropTypes.func.isRequired, path: PropTypes.string.isRequired, history: PropTypes.object, };