Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/packages/input/input.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,28 @@ export const Input = forwardRef((props: Partial<TaroInputProps>, ref) => {
const inputRef = useRef<HTMLInputElement>(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
Expand Down
Loading