From df3da3ac2a92acd7d14c501d20d2a45915041193 Mon Sep 17 00:00:00 2001 From: Samuel Newman <10959775+mozzius@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:15:54 +0200 Subject: [PATCH] listen globally to clicks rather than blur event --- .../util/post-embeds/VideoEmbedInner.web.tsx | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx b/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx index b140fe2ffa..43e730b3cc 100644 --- a/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx +++ b/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx @@ -203,19 +203,21 @@ function Controls({ onOut: onMouseLeave, } = useInteractionState() const isFullscreen = useFullscreen() - const { - state: hasFocus, - onIn: onFocus, - onOut: onUnfocus, - } = useInteractionState() + const {state: hasFocus, onIn: onFocus, onOut: onBlur} = useInteractionState() const [interactingViaKeypress, setInteractingViaKeypress] = useState(false) const onKeyDown = useCallback(() => { setInteractingViaKeypress(true) }, []) - const onBlur = useCallback(() => { - setInteractingViaKeypress(false) - onUnfocus() - }, [onUnfocus]) + useEffect(() => { + if (interactingViaKeypress) { + document.addEventListener('click', () => setInteractingViaKeypress(false)) + return () => { + document.removeEventListener('click', () => + setInteractingViaKeypress(false), + ) + } + } + }, [interactingViaKeypress]) const autoplayDisabled = useAutoplayDisabled()