we need to create a modal dialog with overlay background in Reactjs as React components.when the user click on the overlay ,the modal should be closed.we need to create the modal in a way that it is reusable React component. somebody plz guide me home i can implement this
-
Take a look at react-bootstrap - it implements the functionality you are searching for.CapCa– CapCa2016-04-20 15:47:55 +00:00Commented Apr 20, 2016 at 15:47
-
do you want this modal to contain always the same html (jsx) structure or specific html for each case?stkvtflw– stkvtflw2016-04-29 12:32:39 +00:00Commented Apr 29, 2016 at 12:32
2 Answers
I highly recommend strolling through react-modal's source https://github.com/reactjs/react-modal for "how to" implement your own.
I've gone down this route of implementing custom modals from scratch a few times myself now, and I must recommend simply pulling in react-modal rather than attempting to reinvent that same wheel [I've since replaced homegrown implementations w/ react-modal]. I've experimented w/ a few different React modal packages and react-modal is fully customizable, battle tested, and has a great API.
I have answered nearly identical questions here: How to: ES6 React Modal and here: React conditional render pattern with some more thoughts/examples/links.
Comments
Just for alternative route you could use the new <dialog> element, the browser support is rather low (http://caniuse.com/#search=dialog), but with polyfill this could be fixed. But this gives quite easy and extendable way to create dialogs, see demo here.