Skip to content
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

Cannot close Modal wrapped inside Button #8738

Closed
oluckyman opened this issue Dec 26, 2017 · 1 comment
Closed

Cannot close Modal wrapped inside Button #8738

oluckyman opened this issue Dec 26, 2017 · 1 comment

Comments

@oluckyman
Copy link

Version

3.0.3

Environment

osx, Chrome

Reproduction link

https://codesandbox.io/s/yn3rzwxn1

Steps to reproduce

Wrap Modal into Button component, as in first example

What is expected?

Modal onOk and onClose callbacks have access to state of the parent component so modal could be closed

What is actually happening?

calling this.setState from onOk and onClose does not changes state of the parent component


when the modal is placed outside Button component it works as expected.

You may suggest do not wrap Modal inside Button component. It's not a problem.
The problem is a large codebase written on ant@2.x and full of <Button><Modal></Button> snippets. It's hard to find and it requires adding redundant <div> wrapper which breaks styles sometimes.

@yesmeck
Copy link
Member

yesmeck commented Dec 27, 2017

Modal used React.createPortal internally, React.createPortal will propagate event to the outer button. You can stop propagation in onOk.

onOk={(e) => {
  e.stopPropagation();
  this.setState({ isOpen1: false })
}}

Further reading facebook/react#11387

@yesmeck yesmeck closed this as completed Dec 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants