ReactModal2 tries to be as minimal as possible. This means it requires a little
bit of setup, but gives you complete flexibility to do what you want.
Let's start off with the actual API of ReactModal2:
<ReactModal2 // A callback that gets called whenever the `esc` key is pressed, or the // backdrop is clicked. onClose={this.handleClose.bind(this)} // Enable/Disable calling `onClose` when the `esc` key is pressed. closeOnEsc={true} // Enable/Disable calling `onClose` when the backdrop is clicked. closeOnBackdropClick={true} // Add a className to either the backdrop or modal element. backdropClassName='my-custom-backdrop-class' modalClassName='my-custom-modal-class' // Add styles to either the backdrop or modal element. backdropStyles={{ my: 'custom', backdrop: 'styles' }} modalStyles={{ my: 'custom', modal: 'styles' }}> ...</ReactModal2
If we use it like this it will simply render those two elements in the dom like
this:
Now this might seem like a lot to do every time you want to render a modal, but
this is by design. You are meant to wrap ReactModal2 with your own component
that you use everywhere. Your component can add it's own DOM, styles,
animations, and behavior.
Required. A callback to handle an event that is attempting to close the modal.
closeOnEsc
Boolean
Should this modal call onClose when the esc key is pressed?
closeOnBackdropClick
Boolean
Should this modal call onClose when the backdrop is clicked?
backdropClassName
String
An optional className for the backdrop element.
modalClassName
String
An optional className for the modal element.
backdropStyles
Object
Optional for the backdrop element.
Accessibility
One of ReactModal2's opinions is that modals should be as accessible as
possible. It does much of the work for you, but there's one little thing you
need to help it with.
In order to "hide" your application from screenreaders while a modal is open
you need to let ReactModal2 what the root element for your application is.
Note: The root element should not contain the GatewayDest or whereever
the modal is getting rendered. This will break all the things.
import ReactModal2 from 'react-modal2';ReactModal2.getApplicationElement = () => document.getElementById('application');
FAQ
How do I close the modal?
ReactModal2 is designed to have no state, if you put it in the DOM then it will
render. So if you don't want to show it then simply do not render it in your
parent component. For this reason there is no isOpen property to pass.