MCPcopy
hub / github.com/reactjs/react-modal

github.com/reactjs/react-modal @v3.16.3 sqlite

repository ↗ · DeepWiki ↗ · release v3.16.3 ↗
148 symbols 282 edges 34 files 0 documented · 0%
README

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 (



      <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>


I am a modal


        <form>
          <input />
          <button>tab navigation</button>
          <button>stays</button>
          <button>inside</button>
          <button>the modal</button>
        </form>
      </Modal>



  );
}

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:

Core symbols most depended-on inside this repo

withModal
called by 78
specs/helper.js
createHTMLElement
called by 25
specs/helper.js
withElementCollector
called by 19
specs/helper.js
tabbable
called by 18
src/helpers/tabbable.js
isDocumentWithReactModalOpenClass
called by 15
specs/helper.js
setAppElement
called by 11
src/components/Modal.js
isHtmlWithReactModalOpenClass
called by 6
specs/helper.js
getParentElement
called by 4
src/components/Modal.js

Shape

Function 90
Method 31
Class 27

Languages

TypeScript91%
Python9%

Modules by API surface

specs/helper.js14 symbols
scripts/changelog.py13 symbols
src/components/Modal.js11 symbols
specs/Modal.spec.js11 symbols
src/components/ModalPortal.js10 symbols
specs/Modal.helpers.spec.js10 symbols
src/helpers/focusManager.js9 symbols
src/helpers/classList.js9 symbols
src/helpers/ariaAppHider.js8 symbols
examples/wc/app.js8 symbols
src/helpers/tabbable.js6 symbols
examples/basic/react-router/index.js6 symbols

Dependencies from manifests, versioned

@webcomponents/custom-elements1.5.0 · 1×
babel-cli6.26.0 · 1×
babel-core6.25.0 · 1×
babel-eslint8.0.1 · 1×
babel-loader7.1.2 · 1×
babel-plugin-add-module-exports0.2.1 · 1×
babel-preset-env1.6.0 · 1×
babel-preset-react6.24.1 · 1×
babel-preset-stage-26.24.1 · 1×
coveralls3.1.0 · 1×
cross-env5.2.1 · 1×
eslint4.8.0 · 1×

For agents

$ claude mcp add react-modal \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact