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,8 +61,13 @@ 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();
return options
.filter((option) =>
option.toString().toLowerCase().startsWith(lowercasePrefix),
)
.map((option) => (
<SelectOption <SelectOption
key={typeof option === "string" ? option : option.key} key={typeof option === "string" ? option : option.key}
value={typeof option === "string" ? option : option.key} value={typeof option === "string" ? option : option.key}
@ -70,6 +75,7 @@ export const SelectControl = <
{typeof option === "string" ? option : option.value} {typeof option === "string" ? option : option.value}
</SelectOption> </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}