diff --git a/components/content/Thread.tsx b/components/content/Thread.tsx index 3f370a3c..c2b0c8cf 100644 --- a/components/content/Thread.tsx +++ b/components/content/Thread.tsx @@ -104,17 +104,18 @@ const Thread = ({ thread, active, setActive, onDelete, finaliseThread }: ThreadP const calculatePosition = () => { if (triggerRef.current) { const rect = triggerRef.current.getBoundingClientRect() - const popupWidth = 355 // Adjust this value based on your actual popup width + console.log(rect) + const popupWidth = 355 const viewportWidth = window.innerWidth - let leftPosition = rect.right + 10 // Position to the right of the thread + let leftPosition = rect.left + 40 if (leftPosition + popupWidth > viewportWidth) { - // If the popup overflows the viewport, adjust to the left + // if the popup is going to expand the viewport then we move it to the left leftPosition = rect.left - popupWidth - 10 } setPopupPosition({ - top: rect.top + window.scrollY, // Account for vertical scroll + top: rect.top + window.scrollY, left: leftPosition, }) } @@ -124,7 +125,7 @@ const Thread = ({ thread, active, setActive, onDelete, finaliseThread }: ThreadP if (active) { calculatePosition() // Calculate the position when the popup is active } - }, [active]) // Recalculate when the active state changes + }, [active]) const sortedComments = useMemo(() => { if (!commentThread) return [] @@ -207,12 +208,12 @@ const Thread = ({ thread, active, setActive, onDelete, finaliseThread }: ThreadP const renderPopup = () => { if (!active) return null - + console.log(popupPosition) return createPortal(