diff --git a/src/renderer/components/ui/autocomplete.tsx b/src/renderer/components/ui/autocomplete.tsx index b033f1ca5..da55b31c1 100644 --- a/src/renderer/components/ui/autocomplete.tsx +++ b/src/renderer/components/ui/autocomplete.tsx @@ -7,7 +7,7 @@ import { CommandList, } from "./command"; import { Check } from "lucide-react"; -import { forwardRef, useState } from "react"; +import { forwardRef, useRef, useState } from "react"; type Props = { options: string[]; @@ -19,10 +19,11 @@ type Props = { export const Autocomplete = forwardRef( ({ options, value, onChange, placeholder }, ref) => { const [selected, setSelected] = useState(false); + const cmdRef = useRef(null); return (
- + ( onValueChange={onChange} onSelect={() => setSelected(true)} className="h-10" - // FIXME: Select hack - onBlur={() => setTimeout(() => setSelected(false), 100)} + onBlur={(e) => { + if (e.relatedTarget === cmdRef.current) { + return; + } + setSelected(false); + }} autoFocus={true} /> {selected && options.length > 0 && ( {options.map((opt) => ( - + { + onChange(val); + setSelected(false); + }} + >