diff options
Diffstat (limited to 'packages/exchange-backoffice-ui/src/handlers/InputSelectMultiple.tsx')
-rw-r--r-- | packages/exchange-backoffice-ui/src/handlers/InputSelectMultiple.tsx | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/packages/exchange-backoffice-ui/src/handlers/InputSelectMultiple.tsx b/packages/exchange-backoffice-ui/src/handlers/InputSelectMultiple.tsx index dd85453e5..8369e509d 100644 --- a/packages/exchange-backoffice-ui/src/handlers/InputSelectMultiple.tsx +++ b/packages/exchange-backoffice-ui/src/handlers/InputSelectMultiple.tsx @@ -4,16 +4,16 @@ import { LabelWithTooltipMaybeRequired, UIFormProps } from "./InputLine.js"; import { useField } from "./useField.js"; import { useState } from "preact/hooks"; -export function InputSelectMultiple( +export function InputSelectMultiple<T extends object, K extends keyof T>( props: { choices: Choice[]; unique?: boolean; max?: number; - } & UIFormProps<Array<string>>, + } & UIFormProps<T, K>, ): VNode { const { name, label, choices, placeholder, tooltip, required, unique, max } = props; - const { value, onChange } = useField<{ [s: string]: Array<string> }>(name); + const { value, onChange } = useField<T, K>(name); const [filter, setFilter] = useState<string | undefined>(undefined); const regex = new RegExp(`.*${filter}.*`, "i"); @@ -21,7 +21,7 @@ export function InputSelectMultiple( return { ...prev, [curr.value]: curr.label }; }, {} as Record<string, string>); - const list = value ?? []; + const list = (value ?? []) as string[]; const filteredChoices = filter === undefined ? undefined @@ -44,7 +44,7 @@ export function InputSelectMultiple( onClick={() => { const newValue = [...list]; newValue.splice(idx, 1); - onChange(newValue); + onChange(newValue as T[K]); setFilter(undefined); }} class="group relative h-5 w-5 rounded-sm hover:bg-gray-500/20" @@ -119,7 +119,7 @@ export function InputSelectMultiple( } const newValue = [...list]; newValue.splice(0, 0, v.value); - onChange(newValue); + onChange(newValue as T[K]); }} // tabindex="-1" |