summaryrefslogtreecommitdiffhomepage
path: root/frontend/src/components/inputs/Selector.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/components/inputs/Selector.tsx')
-rw-r--r--frontend/src/components/inputs/Selector.tsx9
1 files changed, 8 insertions, 1 deletions
diff --git a/frontend/src/components/inputs/Selector.tsx b/frontend/src/components/inputs/Selector.tsx
index 38b48722b..ba253ae64 100644
--- a/frontend/src/components/inputs/Selector.tsx
+++ b/frontend/src/components/inputs/Selector.tsx
@@ -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>
);