What is going on
Modal dialog stays open after clicking close button or outside. Multiple modals stack without closing previous ones. Backdrop remains visible even when modal closes. Z-index issues cause modals to appear behind other content.
Modal state must be properly managed with React state and backdrop click handlers. CSS z-index requires careful layering.
Common causes
- Close button onClick not calling state setter
- Missing or wrong modal state check in render
- Backdrop click handler not closing modal
- Modal z-index conflicts with other elements
- Multiple modals mounting without parent controlling state
How to fix it
Implement controlled modal with proper state:
const [isOpen, setIsOpen] = useState(false);
return (
<>
{isOpen && (
setIsOpen(false)}>
)}
>
);Getting help takes about a minute
No hiring, no back and forth. A real person looks at your app.
-
1
Describe it
Tell us what you need in plain words. You don't have to be technical or have an account to start.
-
2
Free 15-minute call
A verified developer calls you. Many tasks are sorted right there, and it costs nothing.
-
3
Pay after you approve
If there is more to do, you get one fixed price up front. You pay only once you are happy.
Real people, reviewed by hand
Developers who do this every day
Every developer is approved by our team before they can take a task. Describe yours and the first one who is free picks it up.
Get helpQuestions
How do I prevent backdrop from closing modal?
Check click target. Only close if clicking backdrop itself, not child elements. Use e.currentTarget === e.target.
What z-index should modal have?
Backdrop: 40 (z-40), Modal content: 50 (z-50). Adjust relative to other fixed elements on page.