mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-13 08:15:06 +01:00
Removed clear pointer/action when not visible
This commit is contained in:
parent
2a93804fbd
commit
32c6bf12c7
@ -15,13 +15,15 @@ export interface SearchBarProps {
|
||||
|
||||
export const SearchBarInput = forwardRef<HTMLInputElement, SearchBarProps>(
|
||||
(props, ref) => {
|
||||
const [canClear, setCanClear] = useState(false);
|
||||
const [focused, setFocused] = useState(false);
|
||||
const clearButtonRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
function setSearch(value: string) {
|
||||
props.onChange(value, false);
|
||||
const opacity = value.length > 0 ? "1" : "0";
|
||||
clearButtonRef.current!.style.opacity = opacity;
|
||||
setCanClear(value.length > 0);
|
||||
clearButtonRef.current!.style.opacity = canClear ? "1" : "0";
|
||||
clearButtonRef.current!.style.cursor = canClear ? "pointer" : "auto";
|
||||
}
|
||||
|
||||
function refocusSearch() {
|
||||
@ -79,8 +81,10 @@ export const SearchBarInput = forwardRef<HTMLInputElement, SearchBarProps>(
|
||||
<div
|
||||
ref={clearButtonRef}
|
||||
onClick={() => {
|
||||
setSearch("");
|
||||
setTimeout(() => refocusSearch(), 10);
|
||||
if (canClear) {
|
||||
setSearch("");
|
||||
setTimeout(() => refocusSearch(), 10);
|
||||
}
|
||||
}}
|
||||
className="group/clear cursor-pointer absolute p-1 bottom-0 right-2 top-0 flex justify-center my-auto max-h-10 max-w-10 h-full w-full items-center hover:bg-search-hoverBackground active:scale-110 text-search-icon rounded-full opacity-0 transition duration-100"
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user