onRequestClose doesn't appear to work correctly
Based on the the documentation, it sounds like onRequestClose is supposed to be called anytime the modal is closed. However, it appears to be called any time the overlay is clicked and it is never called when the isOpen prop changes from true to false.
Here is code example. If you click on the overlay, you will end up Close handled in the console, even though the modal is still open. If you click the Close Modal button, Close handled doesn't end up in the console, even though the modal has closed.
@asdcdow onRequestClose is also intended to be called from the overlay (so you can decide if the modal should close or not)...and this function is responsible to change the state for the modal.
onRequestClose={() => {
console.log('Close handled');
this.handleCloseModal();
}}
In that case, you may want to change the documentation here. The description makes it sound like whatever is passed to on onRequestClose will be called right before the modal closes (no matter what triggers the closing). However, really it is called whenever the overlay is clicked (whether that will trigger a close or not). I would argue that name should also also be changed to something like onOverlayClick since it doesn't actually have anything to do with whether the modal is closing unless you explicitly add logic to do so.
[Edit] @asdcdow Actually, it's really a callback for the overlay. Rename it would require a major version change, so better fix the documentation. Can you improve the documentation for this?
onRequestClose is also called when ESC is pressed, so it's not only a callback for the overlay.
@asdcdow I think onRequestClose is pretty appropriate. The modal only speaks for itself. If you change isOpen from the outside, then it's not the modal itself requesting to close, therefore the modal shouldn't request anything.
@shivashp has updated the documentation (thanks). Requesting your approvals, @asdcdow and @gustavopch, to close this issue.
@diasbruno I think the docs are pretty clear now.
Thanks for making the usage clearer
I was using "reactstrap" instead of "react-modal", and was missing the toggle event on my Modal element. I had the toggle attribute on my ModalHeader, but not on my Modal tag.
Adding toggle={this.toggle} onto my Modal made the modal go away when clicking off of it , on all devices.