diff --git a/web/js/components/preact/HLSVideoCell.tsx b/web/js/components/preact/HLSVideoCell.tsx index 5f9ba5e0b..ed38ee004 100644 --- a/web/js/components/preact/HLSVideoCell.tsx +++ b/web/js/components/preact/HLSVideoCell.tsx @@ -89,9 +89,31 @@ export function HLSVideoCell({ const [isTogglingEnabled, setIsTogglingEnabled] = useState(false); const canControlPrivacy = stream.can_control_privacy !== false; const privacyResumeButtonRef = useRef(null); + const hadPrivacyFocusRef = useRef(false); + const previousFocusedElementRef = useRef(null); + const tileContainerRef = useRef(null); useEffect(() => { - if (privacyActive) privacyResumeButtonRef.current?.focus(); + if (privacyActive) { + if (!hadPrivacyFocusRef.current) { + const focused = document.activeElement; + previousFocusedElementRef.current = focused instanceof HTMLElement && focused !== document.body + ? focused : null; + } + privacyResumeButtonRef.current?.focus(); + hadPrivacyFocusRef.current = true; + return; + } + + if (!hadPrivacyFocusRef.current) return; + hadPrivacyFocusRef.current = false; + const previous = previousFocusedElementRef.current; + if (previous && previous.isConnected) { + previous.focus(); + } else { + tileContainerRef.current?.focus(); + } + previousFocusedElementRef.current = null; }, [privacyActive]); useEffect(() => { @@ -770,6 +792,7 @@ export function HLSVideoCell({ privacyRequestGenerationRef.current += 1; setIsTogglingEnabled(false); setShowPrivacyConfirm(false); + setShowRefreshConfirm(false); return () => { privacyRequestGenerationRef.current += 1; }; }, [stream.name, streamId]); @@ -886,6 +909,7 @@ export function HLSVideoCell({ return (