Compare general dialog composition, a configurable modal with presentation defaults, and a video-focused modal wrapper.
A form, a confirmation, and a video overlay have different content requirements. react-modal and react-responsive-modal are general modal building blocks. react-modal-video supplies a more specific video-oriented presentation and provider configuration; it is not simply another name for a general form dialog.
react-modal leaves open state and visual design with the application while supplying modal behavior and overlay/content configuration. Configure the application element appropriately and give the dialog an understandable name. The application element setting is not the same as selecting the visual mount location.
Decide how Escape, overlay clicks, initial focus, and return focus should work. A close request still needs application state handling. When a dialog contains forms or nested interfaces, the application also owns validation, submission, and any separate workflow state.
react-responsive-modal uses an open and onClose contract and supplies a distributed stylesheet. Its current props default to allowing Escape and overlay dismissal, blocking background scrolling, showing a close icon, and trapping focus. Centering defaults to false. Options such as initialFocusRef, container, classNames, and styles change the integration deliberately rather than through a replacement import.
Its onClose means the user requested closure; onAnimationEnd describes the completed exit animation. Do not treat those callbacks as the same lifecycle event, especially if application code needs to wait before removing surrounding state.
react-modal-video accepts isOpen, onClose, a channel, and the relevant video information. It provides provider URL construction, aspect-ratio layout, and animation classes. Include its documented stylesheet. The published default rendering uses an iframe unless supplied children replace that content; a custom URL is not evidence that the package automatically constructs a native video element.
Its current React and React DOM peers cover React 17 and the supported React 18 range, not React 19. Check that requirement before adopting it into a newer host. Its published dialog markup also uses area-modal rather than aria-modal; do not assume the feature summary establishes that every emitted dialog attribute is correct for the application. Review the actual markup, labels, and focus behavior of the chosen integration.
Choose a general modal when the application needs arbitrary content and owns its UI structure. Choose the video-specific wrapper when its provider and presentation contract genuinely reduces application work. Neither choice supplies a complete media service or form workflow.
For all three, check repeated open/close behavior, keyboard focus, nested UI, and animation timing in the finished application. A component's available options are not a substitute for deciding the intended user interaction.
Choose this for general application dialogs when you want explicit app-element, focus, overlay, content, and styling configuration.
Choose this for an open/onClose modal with distributed styling and configurable close, scroll, focus, and presentation behavior.
Choose this for a video-focused modal with supported provider URL construction and aspect-ratio presentation, after checking its React host and actual markup.
Accessible modal dialog component for React.JS
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.
The primary documentation for react-modal is the reference book, which describes the API and gives examples of its usage.
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.
There are several demos hosted on CodePen which demonstrate various features of react-modal: