Fix filtering in Select component
Fixes: #27944 Signed-off-by: Hynek Mlnarik <hmlnarik@redhat.com>
This commit is contained in:
parent
84f295e909
commit
9fb766bbce
1 changed files with 16 additions and 10 deletions
|
@ -61,8 +61,13 @@ export const SelectControl = <
|
|||
formState: { errors },
|
||||
} = useFormContext();
|
||||
const [open, setOpen] = useState(false);
|
||||
const convert = () =>
|
||||
options.map((option) => (
|
||||
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}
|
||||
|
@ -70,6 +75,7 @@ export const SelectControl = <
|
|||
{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}
|
||||
|
|
Loading…
Reference in a new issue