From ea9920d9ed0e7b3a3e565623e434e75bd3362f02 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 28 Jun 2020 04:12:01 +0300 Subject: feat: close search on clickaway --- src/components/Header/SearchBar.tsx | 41 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'src/components/Header') diff --git a/src/components/Header/SearchBar.tsx b/src/components/Header/SearchBar.tsx index d240db9..2be8f6f 100644 --- a/src/components/Header/SearchBar.tsx +++ b/src/components/Header/SearchBar.tsx @@ -5,7 +5,8 @@ import { List, ListItem, Paper, - Divider + Divider, + ClickAwayListener } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; import { User } from 'which-types'; @@ -67,27 +68,33 @@ const SearchBar: React.FC = ({ navigate }) => { else setShouldRefetch(true); }; - const handleNavigate = (index: number) => () => { - navigate('profile', results[index]._id); + const handleClose = () => { setQuery(''); setResults([]); }; + const handleNavigate = (index: number) => () => { + navigate('profile', results[index]._id); + handleClose(); + }; + const SearchResults = ( - - - { - results.map((result, index) => ( - <> - - - - {(index < results.length - 1) && } - - )) - } - - + + + + { + results.map((result, index) => ( + <> + + + + {(index < results.length - 1) && } + + )) + } + + + ); return ( -- cgit v1.2.3