diff --git a/src/packages/input/input.taro.tsx b/src/packages/input/input.taro.tsx index d88240e831..d27c75e450 100644 --- a/src/packages/input/input.taro.tsx +++ b/src/packages/input/input.taro.tsx @@ -77,16 +77,28 @@ export const Input = forwardRef((props: Partial, ref) => { const inputRef = useRef(null) const [active, setActive] = useState(false) + // 兼容H5和小程序获取原生input标签 + const getNativeInput = () => { + if (Taro.getEnv() === 'WEB') { + const taroInputCoreEl = inputRef.current as HTMLElement + const inputEl = taroInputCoreEl.querySelector('input') + return inputEl + } + return inputRef.current + } + useImperativeHandle(ref, () => { return { clear: () => { setValue('') }, focus: () => { - inputRef.current?.focus() + const nativeInput = getNativeInput() + nativeInput?.focus() }, blur: () => { - inputRef.current?.blur() + const nativeInput = getNativeInput() + nativeInput?.blur() }, get nativeElement() { return inputRef.current