From b05afc7c3ff33755047973b6e1f338b5cc7cfb95 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 5 Oct 2021 16:37:39 +1100 Subject: [PATCH] make click outside of lightbox close the lightbox --- ts/components/Lightbox.tsx | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/ts/components/Lightbox.tsx b/ts/components/Lightbox.tsx index edb441d6d..84d90e4d1 100644 --- a/ts/components/Lightbox.tsx +++ b/ts/components/Lightbox.tsx @@ -196,12 +196,12 @@ const Icon = ({ export const LightboxObject = ({ objectURL, contentType, - videoRef, + renderedRef, onObjectClick, }: { objectURL: string; contentType: MIME.MIMEType; - videoRef: React.MutableRefObject; + renderedRef: React.MutableRefObject; onObjectClick: (event: any) => any; }) => { const { urlToLoad } = useEncryptedFileFetch(objectURL, contentType); @@ -215,10 +215,10 @@ export const LightboxObject = ({ // auto play video on showing a video attachment useUnmount(() => { - if (!videoRef?.current) { + if (!renderedRef?.current) { return; } - videoRef.current.pause.pause(); + renderedRef.current.pause.pause(); }); if (isImageTypeSupported) { @@ -228,6 +228,7 @@ export const LightboxObject = ({ onDragStart={onDragStart} alt={window.i18n('lightboxImageAlt')} src={urlToLoad} + ref={renderedRef} /> ); } @@ -235,15 +236,15 @@ export const LightboxObject = ({ const isVideoTypeSupported = GoogleChrome.isVideoTypeSupported(contentType); if (isVideoTypeSupported) { if (urlToLoad) { - if (videoRef?.current?.paused) { - void videoRef?.current?.play(); + if (renderedRef?.current?.paused) { + void renderedRef?.current?.play(); } } return (