瀏覽代碼

✨ feat(input): enhance input component with custom onChange handler

- modify InputProps to omit and redefine onChange with value-first parameters
- add handleInput method to extract value and pass to custom onChange
- maintain backward compatibility by calling original onInput if provided
- update props interface to support new onChange signature (value: string, event: any) => void
yourname 4 月之前
父節點
當前提交
c06535d028
共有 1 個文件被更改,包括 14 次插入2 次删除
  1. 14 2
      mini/src/components/ui/input.tsx

+ 14 - 2
mini/src/components/ui/input.tsx

@@ -26,7 +26,7 @@ const inputVariants = cva(
   }
 )
 
-export interface InputProps extends Omit<TaroInputProps, 'className'>, VariantProps<typeof inputVariants> {
+export interface InputProps extends Omit<TaroInputProps, 'className' | 'onChange'>, VariantProps<typeof inputVariants> {
   className?: string
   leftIcon?: string
   rightIcon?: string
@@ -34,10 +34,21 @@ export interface InputProps extends Omit<TaroInputProps, 'className'>, VariantPr
   errorMessage?: string
   onLeftIconClick?: () => void
   onRightIconClick?: () => void
+  onChange?: (value: string, event: any) => void
 }
 
 const Input = forwardRef<any, InputProps>(
-  ({ className, variant, size, leftIcon, rightIcon, error, errorMessage, onLeftIconClick, onRightIconClick, ...props }, ref) => {
+  ({ className, variant, size, leftIcon, rightIcon, error, errorMessage, onLeftIconClick, onRightIconClick, onChange, ...props }, ref) => {
+    const handleInput = (event: any) => {
+      const value = event.detail.value
+      onChange?.(value, event)
+      
+      // 同时调用原始的onInput(如果提供了)
+      if (props.onInput) {
+        props.onInput(event)
+      }
+    }
+
     return (
       <View className="w-full">
         <View className="relative">
@@ -61,6 +72,7 @@ const Input = forwardRef<any, InputProps>(
               leftIcon && 'pl-10',
               rightIcon && 'pr-10',
             )}
+            onInput={handleInput}
             {...props}
           />