TrailerModal
TheTrailerModal component displays movie trailers in a full-screen modal overlay with an embedded YouTube video player. It includes keyboard support, click-outside-to-close, and automatic scroll locking.
Component Overview
Props
Callback function invoked when the modal should close.Signature:
() => voidTriggered by:- Clicking the close button (×)
- Clicking outside the modal content
- Pressing the
Escapekey
Features
Keyboard Support
The modal listens for theEscape key and closes automatically:
Scroll Lock
When the modal opens, page scrolling is disabled to prevent background content from scrolling:Click Outside to Close
Clicking the backdrop closes the modal:stopPropagation() prevents clicks inside the modal content from triggering the close.
YouTube Embed
The trailer is embedded using an iframe with appropriate attributes:- Autoplay support
- Fullscreen mode
- Picture-in-picture
- Proper security permissions
Usage Examples
Basic Usage
In PeliculaCard
Fromsrc/components/PeliculaCard.jsx:46:
In Detail Page
Fromsrc/pages/PeliculaDetailPage.jsx:114:
Full Component Code
Location:src/components/TrailerModal.jsx:1
Styling
The component uses these BEM classes:.modal- Full-screen backdrop overlay.modal__content- Centered modal container.modal__close- Close button (×).modal__title- Modal title header.modal__video-container- Responsive video wrapper.modal__video- iframe element
Responsive Video
The video maintains a 16:9 aspect ratio:YouTube URL Format
Important: Use the embed URL format, not the regular watch URL:- Correct
- Incorrect
https://www.youtube.com/embed/YoHD9XEInc0Converting URLs
If you have a watch URL, convert it:Accessibility
Focus Management
Consider trapping focus within the modal:ARIA Attributes
Common Issues
Video Not Loading
- Wrong URL format: Use embed URL, not watch URL
- HTTPS required: Both your site and YouTube URL must use HTTPS
- Embedding disabled: Some videos don’t allow embedding
Scroll Lock Not Working
Ensure cleanup happens when component unmounts:Event Listener Memory Leak
Always clean up event listeners:Related Components
PeliculaCard
Movie card component that uses TrailerModal
Movie Details
Movie detail page that also uses TrailerModal