Skip to content

Commit

Permalink
fix(v2): fix search input blur on desktop (#1874)
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 authored and yangshun committed Oct 24, 2019
1 parent 262dca3 commit 0e66c90
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ const Search = props => {
}
}, []);

const toggleSearchIconClick = useCallback(() => {
props.handleSearchBarToggle(!props.isSearchBarExpanded);
}, [props.isSearchBarExpanded]);
const toggleSearchIconClick = useCallback(
e => {
if (!searchBarRef.current.contains(e.target)) {
searchBarRef.current.focus();
}

useEffect(() => {
if (props.isSearchBarExpanded) {
searchBarRef.current.focus();
}
}, [props.isSearchBarExpanded]);
props.handleSearchBarToggle(!props.isSearchBarExpanded);
},
[props.isSearchBarExpanded],
);

return isEnabled ? (
<Fragment>
Expand All @@ -78,6 +79,7 @@ const Search = props => {
{'search-bar-expanded': props.isSearchBarExpanded},
{'search-bar': !props.isSearchBarExpanded},
)}
onFocus={toggleSearchIconClick}
onBlur={toggleSearchIconClick}
ref={searchBarRef}
/>
Expand Down

0 comments on commit 0e66c90

Please sign in to comment.