Browse Source

fix: dataset search-input compostion can't work in chrome (#11907)

Co-authored-by: zhaoqingyu.1075 <zhaoqingyu.1075@bytedance.com>
tags/0.14.2
zhu-an 10 months ago
parent
commit
6ded06c6d9
No account linked to committer's email address
1 changed files with 9 additions and 3 deletions
  1. 9
    3
      web/app/components/base/search-input/index.tsx

+ 9
- 3
web/app/components/base/search-input/index.tsx View File

const { t } = useTranslation() const { t } = useTranslation()
const [focus, setFocus] = useState<boolean>(false) const [focus, setFocus] = useState<boolean>(false)
const isComposing = useRef<boolean>(false) const isComposing = useRef<boolean>(false)
const [internalValue, setInternalValue] = useState<string>(value)


return ( return (
<div className={cn( <div className={cn(
white && '!bg-white hover:!bg-white group-hover:!bg-white placeholder:!text-gray-400', white && '!bg-white hover:!bg-white group-hover:!bg-white placeholder:!text-gray-400',
)} )}
placeholder={placeholder || t('common.operation.search')!} placeholder={placeholder || t('common.operation.search')!}
value={value}
value={internalValue}
onChange={(e) => { onChange={(e) => {
setInternalValue(e.target.value)
if (!isComposing.current) if (!isComposing.current)
onChange(e.target.value) onChange(e.target.value)
}} }}
onCompositionStart={() => { onCompositionStart={() => {
isComposing.current = true isComposing.current = true
}} }}
onCompositionEnd={() => {
onCompositionEnd={(e) => {
isComposing.current = false isComposing.current = false
onChange(e.data)
}} }}
onFocus={() => setFocus(true)} onFocus={() => setFocus(true)}
onBlur={() => setFocus(false)} onBlur={() => setFocus(false)}
{value && ( {value && (
<div <div
className='shrink-0 flex items-center justify-center w-4 h-4 cursor-pointer group/clear' className='shrink-0 flex items-center justify-center w-4 h-4 cursor-pointer group/clear'
onClick={() => onChange('')}
onClick={() => {
onChange('')
setInternalValue('')
}}
> >
<XCircle className='w-3.5 h-3.5 text-gray-400 group-hover/clear:text-gray-600' /> <XCircle className='w-3.5 h-3.5 text-gray-400 group-hover/clear:text-gray-600' />
</div> </div>

Loading…
Cancel
Save