medium20 min
Build a Modal
Build a reusable modal dialog component. The modal should render as an overlay on top of the page content, close when clicking the backdrop or pressing Escape, and trap focus within the modal for accessibility. Prevent body scroll when the modal is open.
Skills
useStateuseEffectevent listenersportals
Tests
- Modal is not visible initially
- Opens when the trigger button is clicked
- Closes when clicking the close button
- Closes when clicking the backdrop
- Closes when pressing Escape
Loading editor...