Fix filtering in Select component

Fixes: #27944

Signed-off-by: Hynek Mlnarik <hmlnarik@redhat.com>
This commit is contained in:
Hynek Mlnarik 2024-03-18 14:15:16 +01:00 committed by Hynek Mlnařík
parent 84f295e909
commit 9fb766bbce

View file

@ -61,15 +61,21 @@ export const SelectControl = <
formState: { errors },
} = useFormContext();
const [open, setOpen] = useState(false);
const convert = () =>
options.map((option) => (
<SelectOption
key={typeof option === "string" ? option : option.key}
value={typeof option === "string" ? option : option.key}
>
{typeof option === "string" ? option : option.value}
</SelectOption>
));
const convert = (prefix: string = "") => {
const lowercasePrefix = prefix.toLowerCase();
return options
.filter((option) =>
option.toString().toLowerCase().startsWith(lowercasePrefix),
)
.map((option) => (
<SelectOption
key={typeof option === "string" ? option : option.key}
value={typeof option === "string" ? option : option.key}
>
{typeof option === "string" ? option : option.value}
</SelectOption>
));
};
return (
<FormLabel
name={name}
@ -117,7 +123,7 @@ export const SelectControl = <
}
onFilter={(_, value) => {
onFilter?.(value);
return convert();
return convert(value);
}}
isOpen={open}
variant={variant}