mirror of
https://github.com/morpheus65535/bazarr.git
synced 2024-12-28 18:41:20 +08:00
Fix chip input issue
This commit is contained in:
parent
559ec50c92
commit
1a612d12b8
2 changed files with 9 additions and 1 deletions
|
@ -28,6 +28,7 @@ const ChipInput: FunctionComponent<ChipInputProps> = ({ ...props }) => {
|
|||
onChange?.([...(value ?? []), query]);
|
||||
return query;
|
||||
}}
|
||||
buildOption={(value) => value}
|
||||
></MultiSelector>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -109,6 +109,7 @@ export type MultiSelectorProps<T> = Override<
|
|||
options: readonly SelectorOption<T>[];
|
||||
onChange?: (value: T[]) => void;
|
||||
getkey?: (value: T) => string;
|
||||
buildOption?: (value: string) => T;
|
||||
},
|
||||
Omit<MultiSelectProps, "data">
|
||||
>;
|
||||
|
@ -119,11 +120,15 @@ export function MultiSelector<T>({
|
|||
options,
|
||||
onChange,
|
||||
getkey = DefaultKeyBuilder,
|
||||
buildOption,
|
||||
...select
|
||||
}: MultiSelectorProps<T>) {
|
||||
const labelRef = useRef(getkey);
|
||||
labelRef.current = getkey;
|
||||
|
||||
const buildRef = useRef(buildOption);
|
||||
buildRef.current = buildOption;
|
||||
|
||||
const data = useMemo(
|
||||
() =>
|
||||
options.map<SelectItemWithPayload<T>>(({ value, ...option }) => ({
|
||||
|
@ -150,6 +155,8 @@ export function MultiSelector<T>({
|
|||
const payload = data.find((v) => v.value === value)?.payload;
|
||||
if (payload) {
|
||||
payloads.push(payload);
|
||||
} else if (buildRef.current) {
|
||||
payloads.push(buildRef.current(value));
|
||||
}
|
||||
}
|
||||
onChange?.(payloads);
|
||||
|
@ -159,10 +166,10 @@ export function MultiSelector<T>({
|
|||
|
||||
return (
|
||||
<MultiSelect
|
||||
{...select}
|
||||
value={wrappedValue}
|
||||
defaultValue={wrappedDefaultValue}
|
||||
onChange={wrappedOnChange}
|
||||
{...select}
|
||||
data={data}
|
||||
></MultiSelect>
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue