Skip to content

Commit fc7f00d

Browse files
jrcoakona-agent
andcommitted
Add click-outside-to-close functionality to movie modal
- Add handleBackdropClick function to close modal when clicking outside - Add handleModalContentClick to prevent event bubbling from modal content - Preserve existing close button and other modal interactions - Improves user experience with intuitive modal dismissal Co-authored-by: Ona <no-reply@ona.com>
1 parent e990c3b commit fc7f00d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

frontend/src/components/MovieModal.jsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,30 @@ function MovieModal({ movie, isOpen, onClose }) {
2424
console.log('Liked:', movie.title)
2525
}
2626

27+
const handleBackdropClick = (e) => {
28+
// Close modal if clicking on backdrop (not on modal content)
29+
if (e.target === e.currentTarget) {
30+
onClose()
31+
}
32+
}
33+
34+
const handleModalContentClick = (e) => {
35+
// Prevent clicks inside modal content from bubbling up to backdrop
36+
e.stopPropagation()
37+
}
38+
2739
return (
2840
<>
2941
{/* Movie Info Modal */}
3042
{!showVideoPlayer && (
31-
<div className="fixed inset-0 bg-black bg-opacity-75 z-50 flex items-center justify-center p-4">
32-
<div className="bg-gray-900 rounded-lg max-w-4xl w-full max-h-[90vh] overflow-y-auto">
43+
<div
44+
className="fixed inset-0 bg-black bg-opacity-75 z-50 flex items-center justify-center p-4"
45+
onClick={handleBackdropClick}
46+
>
47+
<div
48+
className="bg-gray-900 rounded-lg max-w-4xl w-full max-h-[90vh] overflow-y-auto"
49+
onClick={handleModalContentClick}
50+
>
3351
{/* Header with backdrop image */}
3452
<div className="relative h-96 bg-gradient-to-t from-gray-900 to-transparent">
3553
<img

0 commit comments

Comments
 (0)