feat: introduce trigger functionality (#27644)
Signed-off-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: Stream <Stream_2@qq.com> Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com> Co-authored-by: zhsama <torvalds@linux.do> Co-authored-by: Harry <xh001x@hotmail.com> Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: yessenia <yessenia.contact@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: WTW0313 <twwu@dify.ai> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -22,7 +22,7 @@ const SearchInput: FC<SearchInputProps> = ({
|
||||
const { t } = useTranslation()
|
||||
const [focus, setFocus] = useState<boolean>(false)
|
||||
const isComposing = useRef<boolean>(false)
|
||||
const [internalValue, setInternalValue] = useState<string>(value)
|
||||
const [compositionValue, setCompositionValue] = useState<string>('')
|
||||
|
||||
return (
|
||||
<div className={cn(
|
||||
@@ -42,17 +42,21 @@ const SearchInput: FC<SearchInputProps> = ({
|
||||
white && '!bg-white placeholder:!text-gray-400 hover:!bg-white group-hover:!bg-white',
|
||||
)}
|
||||
placeholder={placeholder || t('common.operation.search')!}
|
||||
value={internalValue}
|
||||
value={isComposing.current ? compositionValue : value}
|
||||
onChange={(e) => {
|
||||
setInternalValue(e.target.value)
|
||||
if (!isComposing.current)
|
||||
onChange(e.target.value)
|
||||
const newValue = e.target.value
|
||||
if (isComposing.current)
|
||||
setCompositionValue(newValue)
|
||||
else
|
||||
onChange(newValue)
|
||||
}}
|
||||
onCompositionStart={() => {
|
||||
isComposing.current = true
|
||||
setCompositionValue(value)
|
||||
}}
|
||||
onCompositionEnd={(e) => {
|
||||
isComposing.current = false
|
||||
setCompositionValue('')
|
||||
onChange(e.currentTarget.value)
|
||||
}}
|
||||
onFocus={() => setFocus(true)}
|
||||
@@ -64,7 +68,6 @@ const SearchInput: FC<SearchInputProps> = ({
|
||||
className='group/clear flex h-4 w-4 shrink-0 cursor-pointer items-center justify-center'
|
||||
onClick={() => {
|
||||
onChange('')
|
||||
setInternalValue('')
|
||||
}}
|
||||
>
|
||||
<RiCloseCircleFill className='h-4 w-4 text-text-quaternary group-hover/clear:text-text-tertiary' />
|
||||
|
||||
Reference in New Issue
Block a user