Skip to content

Commit ca82492

Browse files
committed
fix(types): 修复类型声明问题
1 parent c5227ce commit ca82492

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/taro-ui/src/components/input/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class AtInput extends React.Component<AtInputProps> {
5252
private inputClearing = false
5353

5454
private handleInput = (event: BaseEventOrig<InputEventDetail>): void =>
55-
this.props.onChange(event.detail.value, event)
55+
this.props.onChange?.(event.detail.value, event)
5656

5757
private handleFocus = (event: BaseEventOrig<FocusEventDetail>): void => {
5858
if (typeof this.props.onFocus === 'function') {
@@ -66,7 +66,7 @@ export default class AtInput extends React.Component<AtInputProps> {
6666
}
6767
if (event.type === 'blur' && !this.inputClearing) {
6868
// fix # 583 AtInput 不触发 onChange 的问题
69-
this.props.onChange(
69+
this.props.onChange?.(
7070
event.detail.value,
7171
event as BaseEventOrig<InputEventDetail>
7272
)
@@ -89,7 +89,7 @@ export default class AtInput extends React.Component<AtInputProps> {
8989

9090
private handleClearValue = (event: ITouchEvent): void => {
9191
this.inputClearing = true
92-
this.props.onChange('', event)
92+
this.props.onChange?.('', event)
9393
}
9494

9595
private handleKeyboardHeightChange = (

packages/taro-ui/types/input.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export interface AtInputProps extends AtComponent, OmitInputProps {
130130
* 输入框值改变时触发的事件,开发者需要通过 onChange 事件来更新 value 值变化,onChange 函数必填。
131131
* 小程序中,如果想改变 value 的值,需要 return value 从而改变输入框的当前值, v2.0.3 版本可以获取 event 参数
132132
*/
133-
onChange: InputFunction<string | number, InputEventDetail, any>
133+
onChange?: InputFunction<string | number, InputEventDetail, any>
134134
/**
135135
* 点击完成按钮时触发,v2.0.3 版本可以获取 event 参数
136136
*/

0 commit comments

Comments
 (0)