Created
November 25, 2025 16:50
-
-
Save carlajarchuleta1-a11y/a4d0e567aa38111e9c5a0802c934bcb8 to your computer and use it in GitHub Desktop.
Modal with react-modal
A Pen by Carla Archuleta on CodePen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ReactModal.setAppElement("#app"); | |
| const MyReactModal = () => { | |
| const [modalIsOpen, setIsOpen] = React.useState(false); | |
| const openModal = () => setIsOpen(true); | |
| const closeModal = () => setIsOpen(false); | |
| return ( | |
| <> | |
| <button onClick={openModal}>Open Modal</button> | |
| <ReactModal | |
| isOpen={modalIsOpen} | |
| onRequestClose={closeModal} | |
| aria={{ | |
| labelledby: "id-modal-title", | |
| modal: "true" | |
| }} | |
| > | |
| <h1 id="id-modal-title">Hello</h1> | |
| <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> | |
| </ReactModal> | |
| </> | |
| ); | |
| }; | |
| /* | |
| * Render the above component into the div#app | |
| */ | |
| ReactDOM.render( | |
| <> | |
| <MyReactModal /> | |
| </>, | |
| document.getElementById("app") | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.13.1/umd/react.production.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.production.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/react-modal/3.11.2/react-modal.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment