diff --git a/src/components/combobox.tsx b/src/components/combobox.tsx index b766aa3..b069dd2 100644 --- a/src/components/combobox.tsx +++ b/src/components/combobox.tsx @@ -1,3 +1,5 @@ +import { useState } from "react" + import { Combobox as BaseCombobox, ComboboxInput as BaseComboboxInput, @@ -5,6 +7,7 @@ import { ComboboxOptions as BaseComboboxOptions, Field, } from "@headlessui/react" +import { CheckIcon } from "lucide-react" import { cn } from "@/utils/classname" import { inter } from "@/utils/fonts" @@ -42,17 +45,27 @@ export const Combobox = ({ onInputChange, errorMessage, }: ComboboxProps) => { + const [query, setQuery] = useState("") + const filteredOptions = !query.length + ? options + : options.filter((option) => option.label.toLowerCase().includes(query.toLowerCase())) + + const handleInputChange = (value: string) => { + setQuery(value) + onInputChange && onInputChange(value) + } + return ( {label && } - + setQuery("")}> ) => option?.label} - onChange={(e) => onInputChange && onInputChange(e.currentTarget.value)} + onChange={(e) => handleInputChange(e.currentTarget.value)} /> ({ inter.variable )} > - {options.map((option) => ( + {filteredOptions.map((option) => ( + {option.label} ))} diff --git a/src/modules/endorsements/create-endorsements/components/skill-list-combobox.tsx b/src/modules/endorsements/create-endorsements/components/skill-list-combobox.tsx index dee914d..73bbdc0 100644 --- a/src/modules/endorsements/create-endorsements/components/skill-list-combobox.tsx +++ b/src/modules/endorsements/create-endorsements/components/skill-list-combobox.tsx @@ -29,11 +29,7 @@ export const SkillListCombobox = ({ label, value, placeholder, errorMessage, onC queryFn: SkillsApi.getAllSkills, }) - const options = - data?.map((skill) => ({ - value: skill.id, - label: skill.name, - })) ?? [] + const options = data?.map((skill) => ({ value: skill.id, label: skill.name })) ?? [] const selectedOption = options.find((option) => option.value === value) ?? null