Skip to content

Input组件的onChange事件不能对外暴露事件对象吗? #5755

Answered by awmleer
shervinchen asked this question in Q&A
Discussion options

You must be logged in to vote

上面 @zqran提到了,其实更多的是最常见的使用场景~ onChange 的第一个参数是 string 而不是原生 event,在大多数情况下使用起来都会更简单的一些,毕竟一般情况下,大家是为了取到 input 变化的那个“值”,特别是和 Form 配合使用的时候,会省心很多

除此之外的话,这样设计还是为了和其他组件尽量保持一致,避免学习成本和认知成本,因为几乎所有的“表单”类型的组件,props.value: V props.onChange(value: V) props.defaultValue: V,这三个类型 V 都是一致的(例如对应到 Input 组件的话,V 就是 string

至于 @shervinchen 你所说的希望在某些情况下能接触到原生的事件,其实倒是可以让 Input 的 onChange 增加第二个参数:onChange: (value: string, event: Event)

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
4 replies
@shervinchen
Comment options

@shervinchen
Comment options

@zqran
Comment options

@shervinchen
Comment options

Comment options

You must be logged in to vote
4 replies
@shervinchen
Comment options

@shervinchen
Comment options

@shervinchen
Comment options

@awmleer
Comment options

Answer selected by miracles1919
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants