未验证 提交 f621e71c 编写于 作者: V vickyYe 提交者: GitHub

fix: textarea 组件 change、focus、blur 事件改为 onChange、onFocus、onBlur (#163)

* fix: 修改textarea组件change、focus、blur事件为onChange、onFocus、onBlur
上级 d36d59ce
......@@ -64,13 +64,13 @@ const TextAreaDemo = () => {
defaultValue={value1}
className="text-1"
style={{ fontSize: '12px' }}
change={(value, event) => {
onChange={(value, event) => {
change(value, event)
}}
blur={() => {
onBlur={() => {
console.log('blur')
}}
focus={() => {
onFocus={() => {
console.log('focus')
}}
/>
......
......@@ -63,6 +63,6 @@ const [value1, UpdateValue1] = useState('')
| 名称 | 说明 | 回调参数 |
| ------ | -------------- | -------- |
| change | 输入内容时触发 | val |
| focus | 聚焦时触发 | val |
| blur | 失焦时触发 | val |
| onChange | 输入内容时触发 | val |
| onFocus | 聚焦时触发 | val |
| onBlur | 失焦时触发 | val |
......@@ -19,9 +19,9 @@ export interface TextAreaProps {
disabled?: boolean
autosize?: boolean
style?: CSSProperties
change?: (value: any, event: Event) => void
blur?: (event: Event) => void
focus?: (event: Event) => void
onChange?: (value: any, event: Event) => void
onBlur?: (event: Event) => void
onFocus?: (event: Event) => void
}
const defaultProps = {
defaultValue: '',
......@@ -35,7 +35,8 @@ const defaultProps = {
autosize: false,
} as TextAreaProps
export const TextArea: FunctionComponent<
Partial<TextAreaProps> & React.HTMLAttributes<HTMLDivElement>
Partial<TextAreaProps> &
Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>
> = (props) => {
const { locale } = useConfig()
const {
......@@ -50,9 +51,9 @@ export const TextArea: FunctionComponent<
disabled,
autosize,
style,
change,
blur,
focus,
onChange,
onBlur,
onFocus,
} = { ...defaultProps, ...props }
const textareaBem = bem('textarea')
......@@ -74,29 +75,21 @@ export const TextArea: FunctionComponent<
text.value = text.value.substring(0, Number(maxlength))
}
SetInputValue(text.value)
if (change) {
change(text.value, event)
}
onChange && onChange(text.value, event)
}
const textFocus = (event: Event) => {
if (disabled) return
if (readonly) return
if (focus) {
focus(event)
}
onFocus && onFocus(event)
}
const textBlur = (event: Event) => {
if (disabled) return
if (readonly) return
const text = event.target as any
if (change) {
change(text.value, event)
}
if (blur) {
blur(event)
}
onChange && onChange(text.value, event)
onBlur && onBlur(event)
}
return (
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册