admin管理员组文章数量:1298180
Is it possible to have React fire the onChange
event after the focus on an element is lost as opposed to having it on keyUp
(currently, onChange
is an abstraction of any event that manipulates the field value)? keyUp
is a little slow for me, and I think it may help the mobile expereince with what I'm building to switch the firing of that to after the field is focused.
Is it possible to have React fire the onChange
event after the focus on an element is lost as opposed to having it on keyUp
(currently, onChange
is an abstraction of any event that manipulates the field value)? keyUp
is a little slow for me, and I think it may help the mobile expereince with what I'm building to switch the firing of that to after the field is focused.
- Isn't this normally what the 'onBlur' event is for? I'm unfamiliar with the React framework, but I imagine it might support that in some form. – Katana314 Commented Jun 2, 2014 at 15:20
- Sure is. React abstracts events though, it's one of those huge view frameworks – Kyle Hotchkiss Commented Jun 2, 2014 at 15:34
2 Answers
Reset to default 6Are you looking for something like this?
JS Fiddle
I may be interpreting what you're asking for incorrectly, but you should be able to get your values via e.target.value or through using a ref, like:
<input type="text" ref="myValue" onBlur={this.handleChange} />
and then in your handleChange function you'd have something like this:
handleChange: function()
{
var theValue = this.refs.myValue.getDOMNode().value;
//setState, etc. here
}
You could build your own ponent that support this behavior, for example:
var ChangeOnBlurInput = React.createClass({
render: function() {
var options = this.props;
options.onBlur = options.onChange;
// You can also use `transferPropsTo` here, but I've heard it's deprecated
return React.DOM.input.call(React.DOM, options);
}
});
React.renderComponent(
ChangeOnBlurInput({
value: "Nice",
onChange: function(e) { alert(e.target.value) } }),
document.body);
And use it instead of React.DOM.input
wherever you want.
本文标签: javascriptReact Don39t use keyUp for onChange eventsStack Overflow
版权声明:本文标题:javascript - React: Don't use keyUp for onChange events - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741304945a2371312.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论