From 60a5f84f2f17068fd40f68623f750b2f884354b4 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Tue, 14 Mar 2023 21:02:47 +0100 Subject: [PATCH] fix popouts in body instead of video --- src/components/popout/FloatingContainer.tsx | 57 ++++++++++++++------- src/video/components/VideoPlayerBase.tsx | 2 +- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/components/popout/FloatingContainer.tsx b/src/components/popout/FloatingContainer.tsx index 48e4f5cc..0735d912 100644 --- a/src/components/popout/FloatingContainer.tsx +++ b/src/components/popout/FloatingContainer.tsx @@ -1,5 +1,11 @@ import { Transition } from "@/components/Transition"; -import React, { ReactNode, useCallback, useEffect, useRef } from "react"; +import React, { + ReactNode, + useCallback, + useEffect, + useRef, + useState, +} from "react"; import { createPortal } from "react-dom"; interface Props { @@ -10,6 +16,8 @@ interface Props { } export function FloatingContainer(props: Props) { + const [portalElement, setPortalElement] = useState(null); + const ref = useRef(null); const target = useRef(null); useEffect(() => { @@ -34,23 +42,34 @@ export function FloatingContainer(props: Props) { [props] ); - return createPortal( - -
- -
- - - {props.children} - -
-
, - document.body + useEffect(() => { + const element = ref.current?.closest(".popout-location"); + setPortalElement(element ?? document.body); + }, []); + + return ( +
+ {portalElement + ? createPortal( + +
+ +
+ + + {props.children} + +
+
, + portalElement + ) + : null} +
); } diff --git a/src/video/components/VideoPlayerBase.tsx b/src/video/components/VideoPlayerBase.tsx index 2ce6784d..18f34ab0 100644 --- a/src/video/components/VideoPlayerBase.tsx +++ b/src/video/components/VideoPlayerBase.tsx @@ -39,7 +39,7 @@ function VideoPlayerBaseWithState(props: VideoPlayerBaseProps) {