import type { InputProps } from '@langgenius/dify-ui/input' import { cn } from '@langgenius/dify-ui/cn' import { Input } from '@langgenius/dify-ui/input' import { useRef, useState } from 'react' import { useTranslation } from 'react-i18next' type SearchInputProps = { value: string onValueChange: (value: string) => void placeholder?: string className?: string } & Pick export function SearchInput({ placeholder, className, value, onValueChange, autoFocus, 'aria-label': ariaLabel, }: SearchInputProps) { const { t } = useTranslation() const inputRef = useRef(null) const isComposingRef = useRef(false) const compositionCommitRef = useRef(null) const [compositionValue, setCompositionValue] = useState('') const inputValue = isComposingRef.current ? compositionValue : value const handleClear = () => { isComposingRef.current = false compositionCommitRef.current = null setCompositionValue('') onValueChange('') inputRef.current?.focus() } return (
) }