Просмотр исходного кода

✨ feat(combobox): 添加搜索输入变化回调功能

- 为Combobox组件添加onSearchChange属性,支持搜索输入变化时的回调
- 在ActivitySelect组件中使用onSearchChange属性,实现搜索关键词同步更新
yourname 4 месяцев назад
Родитель
Сommit
7ff3d7cd1c
2 измененных файлов с 7 добавлено и 1 удалено
  1. 1 0
      src/client/admin/components/ActivitySelect.tsx
  2. 6 1
      src/client/components/ui/combobox.tsx

+ 1 - 0
src/client/admin/components/ActivitySelect.tsx

@@ -79,6 +79,7 @@ export function ActivitySelect({
       options={activityOptions}
       options={activityOptions}
       value={selectedValue}
       value={selectedValue}
       onValueChange={handleValueChange}
       onValueChange={handleValueChange}
+      onSearchChange={setSearchKeyword}
       placeholder={isLoading ? "加载中..." : placeholder}
       placeholder={isLoading ? "加载中..." : placeholder}
       searchPlaceholder="搜索活动名称..."
       searchPlaceholder="搜索活动名称..."
       emptyMessage="未找到匹配的活动"
       emptyMessage="未找到匹配的活动"

+ 6 - 1
src/client/components/ui/combobox.tsx

@@ -28,6 +28,7 @@ interface ComboboxProps {
   options: ComboboxOption[]
   options: ComboboxOption[]
   value?: string
   value?: string
   onValueChange?: (value: string) => void
   onValueChange?: (value: string) => void
+  onSearchChange?: (search: string) => void
   placeholder?: string
   placeholder?: string
   searchPlaceholder?: string
   searchPlaceholder?: string
   emptyMessage?: string
   emptyMessage?: string
@@ -39,6 +40,7 @@ export function Combobox({
   options,
   options,
   value,
   value,
   onValueChange,
   onValueChange,
+  onSearchChange,
   placeholder = "请选择...",
   placeholder = "请选择...",
   searchPlaceholder = "搜索...",
   searchPlaceholder = "搜索...",
   emptyMessage = "未找到匹配项",
   emptyMessage = "未找到匹配项",
@@ -65,7 +67,10 @@ export function Combobox({
       </PopoverTrigger>
       </PopoverTrigger>
       <PopoverContent className="w-full p-0" align="start">
       <PopoverContent className="w-full p-0" align="start">
         <Command>
         <Command>
-          <CommandInput placeholder={searchPlaceholder} />
+          <CommandInput
+            placeholder={searchPlaceholder}
+            onValueChange={onSearchChange}
+          />
           <CommandList>
           <CommandList>
             <CommandEmpty>{emptyMessage}</CommandEmpty>
             <CommandEmpty>{emptyMessage}</CommandEmpty>
             <CommandGroup>
             <CommandGroup>