Skip to content

Commit

Permalink
fix: 点击 Textarea 容器也会获得焦点
Browse files Browse the repository at this point in the history
  • Loading branch information
cncolder committed May 9, 2020
1 parent 557fb48 commit 8b864b5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react'
import React, { useRef, useMemo } from 'react'
import Taro from '@tarojs/taro'
import classNames from 'classnames'
import { View, Textarea as _Textarea, CommonEventFunction } from '@tarojs/components'
Expand All @@ -19,7 +19,7 @@ export interface TextareaProps

const ENV = Taro.getEnv()

export const Textarea: React.FC<TextareaProps> = props => {
export const Textarea: React.FC<TextareaProps> = (props) => {
const {
className,
style = {},
Expand Down Expand Up @@ -50,9 +50,20 @@ export const Textarea: React.FC<TextareaProps> = props => {
)
const placeholderCls = classNames('placeholder', placeholderClass)

const textareaRef = useRef<any>()

return (
<View className={rootCls} style={style}>
<View
className={rootCls}
style={style}
onClick={() => {
if (textareaRef.current) {
textareaRef.current.focus()
}
}}
>
<_Textarea
ref={textareaRef as any}
className="at-textarea__textarea"
style={textareaStyle}
placeholderClass={placeholderCls}
Expand Down

0 comments on commit 8b864b5

Please sign in to comment.