react-modal icon indicating copy to clipboard operation
react-modal copied to clipboard

Possible to close modal from a child element?

Open hrag opened this issue 6 years ago • 2 comments

Hi all, I have a use case where I need to be able to close the modal, but it should be invoked using a function somewhere, or a click event from a button which is one of the child elements. I can't seem to figure out how to accomplish this after Googling around.

Also, this modal is nested within another component, so there's no access to the state or props.

hrag avatar May 30 '19 23:05 hrag

Hi all, I have a use case where I need to be able to close the modal, but it should be invoked using a function somewhere

Did you try passing the close handler from the modal to the child component and involve that handler in child components?

Also, this modal is nested within another component, so there's no access to the state or props.

You're able to pass these props down like -> parent component -> another component -> child component (where you'd like to use the parent state and call its close event handler)

konekoya avatar May 31 '19 00:05 konekoya

I have implemented this solution https://stackoverflow.com/a/71464748/1770571 and it works properly

salmagomaa avatar Mar 14 '22 08:03 salmagomaa