The last time Hackerfall tried to access this page, it returned a not found error. A cached version of the page is below, or clickhereto continue anyway

Modals in React – ReactJS News

Have you wanted to use some type of modal in React but didn’t know where to start? I’ll be going over a few community-built components that help you create modals.

There’s been a few times I’ve needed a modal in the app I’m building. Thankfully the community has made a few really good components for this. Let’s jump right in to the first:

Elemental UI’s modal

You can check out a demo of it right here. The markup is straight forward:

<Modal isOpen={this.state.modalIsOpen} onCancel={this.toggleModal} backdropClosesModal>
  <ModalHeader text="Live Demo" showCloseButton onClose={this.toggleModal} />
  <form action="#" onSubmit={this.submitForm} noValidate>
      <FormField label="Email">
        <FormInput label="Email" type="email" name="email" ref="email" value={} onChange={updateInput} required />
      <Button onClick={this.toggleModal} type="link-cancel" disabled={this.state.formProcessing}>Cancel</Button>

You can place things in the header or footer just as easily as the body which is nice. I also like the look of it, and Elemental UI as a whole. My biggest gripe about this modal component is that on scrolling the page it disappears.

React Bootstrap

This is probably one that everyone has heard of, as it is one of the oldest React projects. You can find documentation here. It consists of a couple sub components for the header and footer as well. The root modal component expects two props, a boolean called show, and a function to be called onHide.

<Modal show={this.state.showModal} onHide={this.close}>
  <Modal.Header closeButton>
    <Modal.Title>Modal heading</Modal.Title>
    <h4>Text in a modal</h4>
    <Button onClick={this.close}>Close</Button>

The close and show functions are flipping the state:

  this.setState({ showModal: false });

Rackt’s Modal

Rackt’s modal is much simpler than the other two, as seen on the github page.

It doesn’t have any sub components. It accepts isOpen (bool) and onRequestClose (function) as props:

<Modal isOpen={bool} onRequestClose={fn} closeTimeoutMS={n}>
  <h1>Modal Content</h1>

Those are the top three modal components out there. At my work, we use popovers a lot. My coworker made his own component called reactable-popover that has been really useful for me. Sadly he’s always too busy to document anything, so I’ll throw in a little example here.


The props are very self explanatory, except for toggleButton. It expects a component or some jsx to be passed into it.

Boron Modal

Boron comes out of the box with some animations.

var Modal = require('boron/DropModal');
var Example = React.createClass({
  showModal: function(){;
  hideModal: function(){
  render: function() {
    return (
        <button onClick={this.showModal}>Open</button>
        <Modal ref="modal">
          <h2>I am a dialog</h2>
          <button onClick={this.hideModal}>Close</button>

The author suggests placing a ref on the modal. Then you can open and close it via and this.refs.modal.hide().

React Modal Dialog

React modal dialog is an idiomatic way to show dialogs. You simply render the dialog component in when you want to show one, and don’t render it when you don’t. This is achieved through through a ‘portal’.

import {ModalContainer, ModalDialog} from 'react-modal-dialog';

// In a render function:
class Button extends React.Component {
  state = {
    isShowingDialog: false
  render() {
    return (
      <a className="button">
                <span>Button Text</span>

        {this.state.isShowingDialog ?
          <ModalContainer onClose={...}>
            <ModalDialog onClose={...}>
            <h1>Dialog Content</h1>
            <p>More Content. Anything goes here</p>
        : null}

Thanks for checking out the post, don’t forget to follow @ReactJSNews for more content! Leave a comment if you have any suggestions. As always, you’re welcome to modify this post (or write your own!) by sending in a pull request on github!

Simple React Modal

After writing this post, I realized many of these modals have limitations and force things on you. In my case, most forced some css rules that I could not override. For this reason, I made my own. You can view a demo here with the default styling.

import Modal from 'simple-modal'
import 'simple-react-modal/dist/modal' //import the base css

//inside the render
<a onClick={()=>{}}>Open Modal</a>
<Modal ref="modal"
className="simple-modal your-class"

<a className="close" onClick={()=>{this.refs.modal.hide()}}>X</a>


You can import the base css, or not at all and completely design it yourself. It’s more of a skeleton.

Continue reading on