react-modal
Accessible modal dialog component for React.JS
Last updated 10 years ago by mzabriskie .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install react-modal 
SYNC missed versions from official npm registry.

react-modal

Accessible modal dialog component for React.JS

Build Status Coverage Status gzip size Join the chat at https://gitter.im/react-modal/Lobby

Table of Contents

Installation

To install, you can use npm or yarn:

$ npm install --save react-modal
$ yarn add react-modal

To install react-modal in React CDN app:

  • Add this CDN script tag after React CDN scripts and before your JS files (for example from cdnjs):

       <script src="https://cdnjs.cloudflare.com/ajax/libs/react-modal/3.14.3/react-modal.min.js"
       integrity="sha512-MY2jfK3DBnVzdS2V8MXo5lRtr0mNRroUI9hoLVv2/yL3vrJTam3VzASuKQ96fLEpyYIT4a8o7YgtUs5lPjiLVQ=="
       crossorigin="anonymous"
       referrerpolicy="no-referrer"></script>
    
  • Use <ReactModal> tag inside your React CDN app.

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 (https://reactcommunity.org/react-modal/accessibility/)
Modal.setAppElement('#yourAppElement');

function App() {
  let subtitle;
  const [modalIsOpen, setIsOpen] = React.useState(false);

  function openModal() {
    setIsOpen(true);
  }

  function afterOpenModal() {
    // references are now sync'd and can be accessed.
    subtitle.style.color = '#f00';
  }

  function closeModal() {
    setIsOpen(false);
  }

  return (
    <div>
      <button onClick={openModal}>Open Modal</button>
      <Modal
        isOpen={modalIsOpen}
        onAfterOpen={afterOpenModal}
        onRequestClose={closeModal}
        style={customStyles}
        contentLabel="Example Modal"
      >
        <h2 ref={(_subtitle) => (subtitle = _subtitle)}>Hello</h2>
        <button onClick={closeModal}>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.render(<App />, appElement);

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:

Current Tags

  • 3.16.3                                ...           latest (a year ago)
  • 3.0.0-rc2                                ...           next (9 years ago)

116 Versions

  • 3.16.3                                ...           a year ago
  • 3.16.2                                ...           a year ago
  • 3.16.1                                ...           3 years ago
  • 3.15.1                                ...           4 years ago
  • 3.14.4                                ...           4 years ago
  • 3.14.3                                ...           5 years ago
  • 3.14.2                                ...           5 years ago
  • 3.14.1                                ...           5 years ago
  • 3.13.1                                ...           5 years ago
  • 3.12.1                                ...           5 years ago
  • 3.11.2                                ...           6 years ago
  • 3.11.1                                ...           6 years ago
  • 3.10.1                                ...           7 years ago
  • 3.9.1                                ...           7 years ago
  • 3.8.2                                ...           7 years ago
  • 3.8.1                                ...           7 years ago
  • 3.7.1                                ...           7 years ago
  • 3.6.1                                ...           8 years ago
  • 3.5.1                                ...           8 years ago
  • 3.4.5                                ...           8 years ago
  • 3.4.4                                ...           8 years ago
  • 3.4.3                                ...           8 years ago
  • 3.4.2                                ...           8 years ago
  • 3.4.1                                ...           8 years ago
  • 3.3.2                                ...           8 years ago
  • 3.3.1                                ...           8 years ago
  • 3.2.1                                ...           8 years ago
  • 3.1.13                                ...           8 years ago
  • 3.1.12                                ...           8 years ago
  • 3.1.11                                ...           8 years ago
  • 3.1.10                                ...           8 years ago
  • 3.1.9                                ...           8 years ago
  • 3.1.8                                ...           8 years ago
  • 3.1.7                                ...           8 years ago
  • 3.1.6                                ...           8 years ago
  • 3.1.5                                ...           8 years ago
  • 3.1.4                                ...           8 years ago
  • 3.1.3                                ...           8 years ago
  • 3.1.2                                ...           8 years ago
  • 3.1.0                                ...           8 years ago
  • 3.0.4                                ...           8 years ago
  • 3.0.3                                ...           8 years ago
  • 3.0.2                                ...           8 years ago
  • 3.0.0                                ...           9 years ago
  • 2.4.1                                ...           9 years ago
  • 3.0.0-rc2                                ...           9 years ago
  • 3.0.0-rc1                                ...           9 years ago
  • 3.0.0-alpha                                ...           9 years ago
  • 2.3.3                                ...           9 years ago
  • 2.3.2                                ...           9 years ago
  • 2.3.1                                ...           9 years ago
  • 2.2.4                                ...           9 years ago
  • 2.2.3                                ...           9 years ago
  • 2.2.2                                ...           9 years ago
  • 2.2.1                                ...           9 years ago
  • 2.2.0                                ...           9 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.7                                ...           9 years ago
  • 2.0.6                                ...           9 years ago
  • 2.0.2                                ...           9 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.9.7                                ...           9 years ago
  • 1.9.6                                ...           9 years ago
  • 1.9.5                                ...           9 years ago
  • 1.9.4                                ...           9 years ago
  • 1.9.3                                ...           9 years ago
  • 1.9.2                                ...           9 years ago
  • 1.9.1                                ...           9 years ago
  • 1.8.1                                ...           9 years ago
  • 1.7.13                                ...           9 years ago
  • 1.7.12                                ...           9 years ago
  • 1.7.11                                ...           9 years ago
  • 1.7.10                                ...           9 years ago
  • 1.7.9                                ...           9 years ago
  • 1.7.8                                ...           9 years ago
  • 1.7.7                                ...           9 years ago
  • 1.7.6                                ...           9 years ago
  • 1.7.5                                ...           9 years ago
  • 1.7.4 [deprecated]           ...           9 years ago
  • 1.7.3                                ...           9 years ago
  • 1.7.2                                ...           9 years ago
  • 1.7.1                                ...           9 years ago
  • 1.7.0                                ...           9 years ago
  • 1.6.5                                ...           9 years ago
  • 1.6.4                                ...           9 years ago
  • 1.6.3                                ...           9 years ago
  • 1.6.2 [deprecated]           ...           9 years ago
  • 1.6.1                                ...           9 years ago
  • 1.6.0 [deprecated]           ...           9 years ago
  • 1.5.2                                ...           10 years ago
  • 1.5.1                                ...           10 years ago
  • 1.5.0                                ...           10 years ago
  • 1.4.0                                ...           10 years ago
  • 1.3.0                                ...           10 years ago
  • 1.2.1                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.2                                ...           10 years ago
  • 1.1.1                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.6.1                                ...           10 years ago
  • 0.6.0 [deprecated]           ...           10 years ago
  • 0.5.0                                ...           11 years ago
  • 0.3.0                                ...           11 years ago
  • 0.2.0                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
  • 0.0.7                                ...           11 years ago
  • 0.0.6                                ...           11 years ago
  • 0.0.5                                ...           11 years ago
  • 0.0.4                                ...           11 years ago
  • 0.0.3                                ...           11 years ago
  • 0.0.2                                ...           12 years ago
  • 0.0.1                                ...           12 years ago
  • 0.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 3
Last Day 0
Last Week 20
Last Month 24
Dependencies (3)
Dev Dependencies (20)

Copyright 2013 - present © cnpmjs.org | Home |