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