0.5.4 • Public • Published


A React Modal Wrapper that uses FlexBox to keep it's position, BYOM (bring-your-own-modal). Based off the Portal component by Tajo. Note: This uses flexbox so browser support is iffy. Will post a compatibility table at some point.


npm install react-modal-wrapper --save


import React from 'react';
import ReactDOM from 'react-dom';
import FlexModalWrapper from 'react-modal-wrapper';
import 'react-modal-wrapper/dist/main.css'; // to load default styles
const Modal = React.createClass({
  render() {
    return (
        <p><button onClick={this.props.closeModal}>Close this</button></p>
let App = React.createClass({
  render() {
    const button = <button>Open Modal</button>;
    return (
      <div className="example">
        <FlexModalWrapper className="modal" closeOnEsc closeOnOutsideClick openByClickOn={button}>
            <p>this react component is appended to the document body</p>
ReactDOM.render(<App/>, document.getElementById('container'));

With accompanying CSS:

.modal {
  background-color: #fff;
  border: 1px solid #000;
  box-shadow: 0 3px 9px rgba(0,0,0,0.5);
  padding: 25px;


children : React.PropTypes.element.isRequired

The modal expects a single child which is the modal component that you provide.

isOpened : React.PropTypes.bool

If true, the modal will be open, if false, the modal will be closed. You have to manage closing it (via state management) so to make life easier see openByClickOn

openByClickOn : React.PropTypes.element

Renders the passed element where you actually use the FlexModalWrapper (see example above). It's onClick handler opens the modal. The prop closeModal gets passed into your Modal so you can call this.props.closeModal to close the modal.

closeOnEsc : React.PropTypes.bool

If true, the modal can be closed by pressing the ESC key.

closeOnOutsideClick : React.PropTypes.bool

If true, the modal can be closed by click anywhere outside the modal.

onClose : React.PropTypes.func

Callback that is called when the portal closes.

className : React.PropTypes.string

The class that gets set to the element that wraps your modal. Note: this is where you'll want to set box-shadow CSS since it wraps your modal with exactly the same dimensions, any box-shadow on your modal won't show passed the borders of the wrapping element so the box-shadow would appear to just be a black line typically.

useOverlay : React.PropTypes.bool (defaults to true)

If true, will use an overlay that gets placed behind the modal. Will use default style or use passed overlayStyle or overlayClassName for the overlay style.

overlayStyle : React.PropTypes.object

Object that will be used as inline styles for the overlay (only if useOverlay is true)

overlayClassName : React.PropTypes.string

String that will be used as the class for the overlay (only if useOverlay is true)

Testing and Examples

You can test the examples by running

npm start

and then going to localhost:8080/basic/ in your browser. There'll be buttons for different modals

To test run

npm test

Note: Tests are not yet implemented


npm i react-modal-wrapper

DownloadsWeekly Downloads






Last publish


  • 1stdibs
  • petejodo