From fc5b0e4113c369fd410cfc7f45d65e1610f7703a Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 28 Aug 2025 22:36:21 +0200 Subject: [PATCH] ui/multisearch: make controlled for now --- .../src/components/Search/MultipleSearch.tsx | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/pkgs/clan-app/ui/src/components/Search/MultipleSearch.tsx b/pkgs/clan-app/ui/src/components/Search/MultipleSearch.tsx index b1698c435..60eea462a 100644 --- a/pkgs/clan-app/ui/src/components/Search/MultipleSearch.tsx +++ b/pkgs/clan-app/ui/src/components/Search/MultipleSearch.tsx @@ -2,7 +2,15 @@ import Icon from "../Icon/Icon"; import { Button } from "../Button/Button"; import styles from "./Search.module.css"; import { Combobox } from "@kobalte/core/combobox"; -import { createMemo, createSignal, For, JSX, Match, Switch } from "solid-js"; +import { + createEffect, + createMemo, + createSignal, + For, + JSX, + Match, + Switch, +} from "solid-js"; import { createVirtualizer, VirtualizerOptions } from "@tanstack/solid-virtual"; import { CollectionNode } from "@kobalte/core/*"; import cx from "classnames"; @@ -11,13 +19,16 @@ import { Loader } from "../Loader/Loader"; export interface Option { value: string; label: string; + disabled?: boolean; } export interface ItemRenderOptions { selected: boolean; + disabled: boolean; } export interface SearchMultipleProps { + values: T[]; // controlled values onChange: (values: T[]) => void; options: T[]; renderItem: (item: T, opts: ItemRenderOptions) => JSX.Element; @@ -29,12 +40,13 @@ export interface SearchMultipleProps { headerChildren?: JSX.Element; loading?: boolean; loadingComponent?: JSX.Element; + divider?: boolean; } export function SearchMultiple( props: SearchMultipleProps, ) { // Controlled input value, to allow resetting the input itself - const [values, setValues] = createSignal(props.initialValues || []); + // const [values, setValues] = createSignal(props.initialValues || []); const [inputValue, setInputValue] = createSignal(""); let inputEl: HTMLInputElement; @@ -60,21 +72,23 @@ export function SearchMultiple( return item?.rawValue?.value || `item-${index}`; }, estimateSize: () => 42, - gap: 6, + gap: 0, overscan: 5, ...props.virtualizerOptions, }); return newVirtualizer; }); - + createEffect(() => { + console.log("multi values:", props.values); + }); return ( multiple - value={values()} + value={props.values} onChange={(values) => { - setValues(() => values); - // setInputValue(value ? value.label : ""); + // setValues(() => values); + console.log("onChange", values); props.onChange(values); }} class={styles.searchContainer} @@ -83,6 +97,7 @@ export function SearchMultiple( optionValue="value" optionTextValue="label" optionLabel="label" + optionDisabled={"disabled"} sameWidth={true} open={true} gutter={7} @@ -183,11 +198,16 @@ export function SearchMultiple( return null; } const isSelected = () => - values().some((v) => v.value === item.rawValue.value); + props.values.some( + (v) => v.value === item.rawValue.value, + ); return ( ( > {props.renderItem(item.rawValue, { selected: isSelected(), + disabled: item.disabled, })} );