From f30c1df9bf432e45c9ccbb7c78389019b31270a6 Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Mon, 5 Feb 2024 14:53:47 -0300 Subject: [PATCH] Feat: make input dropdown filter with text --- .../src/components/inputComponent/index.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/components/inputComponent/index.tsx b/src/frontend/src/components/inputComponent/index.tsx index fb7e7bfca..720b41eb3 100644 --- a/src/frontend/src/components/inputComponent/index.tsx +++ b/src/frontend/src/components/inputComponent/index.tsx @@ -7,6 +7,7 @@ import { classNames } from "../../utils/utils"; import IconComponent from "../genericIconComponent"; import { Input } from "../ui/input"; + export default function InputComponent({ autoFocus = false, onBlur, @@ -26,6 +27,9 @@ export default function InputComponent({ const [pwdVisible, setPwdVisible] = useState(false); const refInput = useRef(null); const [showOptions, setShowOptions] = useState(false); + const [filteredOpts, setFilteredValue] = useState(["key", "key2", "key3", "key4", "key5"]); + + // Clear component state useEffect(() => { if (disabled && value !== "") { @@ -33,11 +37,16 @@ export default function InputComponent({ } }, [disabled]); + + const filteredOptions = filteredOpts.filter((option) => option.toLowerCase().includes(value.toLowerCase())) + + function onInputLostFocus(event): void { if (onBlur) onBlur(event); setShowOptions(false); } + return (
{isForm ? ( @@ -79,7 +88,7 @@ export default function InputComponent({ id={id} ref={refInput} type="text" - onBlur={(e) => setShowOptions(false)} + onBlur={onInputLostFocus} value={value} autoFocus={autoFocus} disabled={disabled} @@ -96,7 +105,6 @@ export default function InputComponent({ placeholder={password && editNode ? "Key" : placeholder} onChange={(e) => { onChange(e.target.value); - setShowOptions(false); }} onKeyDown={(e) => { handleKeyDown(e, value, ""); @@ -105,7 +113,7 @@ export default function InputComponent({ onFocus={() => setShowOptions(true)} /> { - /* options.length > 0 */ true ? ( + /* options.length > 0 && filteredOptions.length > 0 */ true ? ( { onChange(val); @@ -128,7 +136,7 @@ export default function InputComponent({ false ? "mb-2 w-[250px]" : "absolute w-full" )} > - {["key", "key2", "key3", "key4", "key5"].map( + {filteredOptions.map( (option, id) => ( + {selected ? ( )} + + {password && (