Skip to content

Commit

Permalink
Merge pull request #232 from easyops-cn/steve/clear-btn-on-mobile
Browse files Browse the repository at this point in the history
fix: hide clear button on small screen when input is not focused
  • Loading branch information
weareoutman authored Jul 20, 2022
2 parents c15ae08 + c69fbf6 commit 65f8a26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ html[data-theme="dark"] .noResultsIcon {
}

@media (max-width: 576px) {
.searchBarContainer:not(.focused) .searchClearButton,
.searchHintContainer {
display: none;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,17 @@ export default function SearchBar({
});
}, [location.search, location.pathname]);

const [focused, setFocused] = useState(false);

const onInputFocus = useCallback(() => {
focusAfterIndexLoaded.current = true;
loadIndex();
setFocused(true);
handleSearchBarToggle?.(true);
}, [handleSearchBarToggle, loadIndex]);

const onInputBlur = useCallback(() => {
setFocused(false);
handleSearchBarToggle?.(false);
}, [handleSearchBarToggle]);

Expand Down Expand Up @@ -300,6 +304,7 @@ export default function SearchBar({
<div
className={clsx("navbar__search", styles.searchBarContainer, {
[styles.searchIndexLoading]: loading && inputChanged,
[styles.focused]: focused,
})}
>
<input
Expand Down

0 comments on commit 65f8a26

Please sign in to comment.