mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 16:38:58 +08:00
fix: prevent onChange during IME composition (#10059)
This commit is contained in:
parent
32ebea91ff
commit
18424dd82f
@ -1,5 +1,5 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import { useState } from 'react'
|
import { useRef, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { RiSearchLine } from '@remixicon/react'
|
import { RiSearchLine } from '@remixicon/react'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
@ -12,6 +12,7 @@ type SearchInputProps = {
|
|||||||
onChange: (v: string) => void
|
onChange: (v: string) => void
|
||||||
white?: boolean
|
white?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const SearchInput: FC<SearchInputProps> = ({
|
const SearchInput: FC<SearchInputProps> = ({
|
||||||
placeholder,
|
placeholder,
|
||||||
className,
|
className,
|
||||||
@ -21,6 +22,7 @@ const SearchInput: FC<SearchInputProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [focus, setFocus] = useState<boolean>(false)
|
const [focus, setFocus] = useState<boolean>(false)
|
||||||
|
const isComposing = useRef<boolean>(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn(
|
<div className={cn(
|
||||||
@ -45,7 +47,14 @@ const SearchInput: FC<SearchInputProps> = ({
|
|||||||
placeholder={placeholder || t('common.operation.search')!}
|
placeholder={placeholder || t('common.operation.search')!}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
onChange(e.target.value)
|
if (!isComposing.current)
|
||||||
|
onChange(e.target.value)
|
||||||
|
}}
|
||||||
|
onCompositionStart={() => {
|
||||||
|
isComposing.current = true
|
||||||
|
}}
|
||||||
|
onCompositionEnd={() => {
|
||||||
|
isComposing.current = false
|
||||||
}}
|
}}
|
||||||
onFocus={() => setFocus(true)}
|
onFocus={() => setFocus(true)}
|
||||||
onBlur={() => setFocus(false)}
|
onBlur={() => setFocus(false)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user