-
Notifications
You must be signed in to change notification settings - Fork 169
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
Error with event bubbling #15
Comments
this.refs.portal.closePortal() This is bad design and it will break with React 0.14 since refs will return underlying DOM nodes and not React components anymore. There are two other and better ways: Put <div onClick={function () { }}> // it works without the handler
<button ref="close" type="button" onClick={this.handleClose}>Close</button>
</div> into a new component and then you can use <button ref="close" type="button" onClick={this.props.closePortal}>Close</button> or if you don't want to create a new component for some reason, you can use the prop <span onClick={(function(e) {this.setState({isOpened: true})}).bind(this)}>
<Portal isOpened={this.state.isOpened}>
<div onClick={function () { }}> // should work now
<button ref="close" type="button" onClick={(function(e) {this.setState({isOpened: false})}).bind(this)}>Close</button>
</div>
</Portal> I didn't test the code above, so I'm sorry for possible typos. |
Works perfectly, thanks!
This only applies to native DOM components, not custom components:
|
There's an error happening when a parent of the child which is closing the portal has an
onClick
handler:I created a demo where you can run this test.
The text was updated successfully, but these errors were encountered: