feat: show active panel when searchBar is in focus (#806)

* feat: Show active panel when searchBar is in focus

* refactor: rename
This commit is contained in:
ChasLui
2022-12-21 18:36:08 +08:00
committed by GitHub
parent 90d0ccc2e8
commit 1838e616fd
2 changed files with 18 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ const SearchBar = () => {
const memoType = locationStore.state.query.type; const memoType = locationStore.state.query.type;
const [queryText, setQueryText] = useState(""); const [queryText, setQueryText] = useState("");
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
const [isFocus, setIsFocus] = useState(false);
useEffect(() => { useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => { const handleKeyDown = (event: KeyboardEvent) => {
@@ -53,8 +54,16 @@ const SearchBar = () => {
locationStore.setTextQuery(text.length === 0 ? undefined : text); locationStore.setTextQuery(text.length === 0 ? undefined : text);
}; };
const handleFocus = () => {
setIsFocus(true);
};
const handleBlur = () => {
setIsFocus(false);
};
return ( return (
<div className="search-bar-container"> <div className={`search-bar-container ${isFocus ? "is-focus" : ""}`}>
<div className="search-bar-inputer"> <div className="search-bar-inputer">
<Icon.Search className="icon-img" /> <Icon.Search className="icon-img" />
<input <input
@@ -65,6 +74,8 @@ const SearchBar = () => {
ref={inputRef} ref={inputRef}
value={queryText} value={queryText}
onChange={handleTextQueryInput} onChange={handleTextQueryInput}
onFocus={handleFocus}
onBlur={handleBlur}
/> />
</div> </div>
<div className="quickly-action-wrapper"> <div className="quickly-action-wrapper">

View File

@@ -8,6 +8,12 @@
} }
} }
&.is-focus {
> .quickly-action-wrapper {
@apply flex;
}
}
> .search-bar-inputer { > .search-bar-inputer {
@apply h-9 flex flex-row justify-start items-center w-full py-2 px-3 sm:px-4 rounded-full sm:rounded-lg bg-zinc-200 dark:bg-zinc-700; @apply h-9 flex flex-row justify-start items-center w-full py-2 px-3 sm:px-4 rounded-full sm:rounded-lg bg-zinc-200 dark:bg-zinc-700;