react-modal
Accessible modal dialog component for React.JS
Table of Contents
Installation
To install, you can use npm or yarn:
$ npm install --save react-modal
$ yarn add react-modal
API documentation
The primary documentation for react-modal is the reference book, which describes the API and gives examples of its usage.
Examples
Here is a simple example of react-modal being used in an app with some custom styles and focusable input elements within the modal content:
import React from 'react';import ReactDOM from 'react-dom';import Modal from 'react-modal'; const customStyles = content : top : '50%' left : '50%' right : 'auto' bottom : 'auto' marginRight : '-50%' transform : 'translate(-50%, -50%)' ; // Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/)Modal { var subtitle; const modalIsOpensetIsOpen = React; { ; } { // references are now sync'd and can be accessed. subtitlestylecolor = '#f00'; } { ; } return <div> <button =>Open Modal</button> <Modal = = = = ="Example Modal" > <h2 =>Hello</h2> <button =>close</button> <div>I am a modal</div> <form> <input /> <button>tab navigation</button> <button>stays</button> <button>inside</button> <button>the modal</button> </form> </Modal> </div> ;} ReactDOM;You can find more examples in the examples directory, which you can run in a
local development server using npm start or yarn run start.
Demos
There are several demos hosted on CodePen which demonstrate various features of react-modal: