-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix input textarea search autofocus bug #1103
Conversation
@pingan1927, thanks for your PR! By analyzing the history of the files in this pull request, we identified @yiminghe, @afc163 and @benjycui to be potential reviewers. |
}, 0); | ||
if (!('focused' in this.props)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
话说这种判断为什么要用 in
? 直接 this.props.focused 不行吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否存在,与布尔值结果还是有区别的吧。这个if我记得是承玉大神加进来的,我很想删掉..感觉没有用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们的文档写的 focused bool false
, 当然是应该判断 true false,而不是判断存在
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
focused?: boolean;
?指的是可以没有,有的话是boolean
类型
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有就是 undefined,同样是false, this.props.focused 的判断就够了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最终显示结果是一样的。
但是写成 if (!this.props.focused)
的话,<Foo focused={fasle} />
也会去 setState
,区别在这里。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在这里 <Foo focused={fasle} />
去 setState 看起来是合理的吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对的,�我搞错了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ @,重新捋一下:
情况一:
<Foo />
;onBlur
后需要去更新this.state.focus
;
情况二(focused 受控):
<Foo focused={this.state.focused} onBlur={this.handleBlur} onFocus={this.handleFocus} />
;onBlur
的时候如果setState
了, 在componentWillRecevie
的时候还会去setState
一次,会多一次setState
。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还没看代码,但如果是你说的2受控模式的话,内部的onBlur是不应该setState的,应该全部从props接收再设置
First of all, thanks for your contribution! :-)
Please makes sure these boxes are checked before submitting your PR, thank you!
npm run lint
and fix those errors before submitting in order to keep consistent code style.