diff --git a/app/components/ResizingHeightContainer.tsx b/app/components/ResizingHeightContainer.tsx index 39c3efcb75..8f6ef7045a 100644 --- a/app/components/ResizingHeightContainer.tsx +++ b/app/components/ResizingHeightContainer.tsx @@ -1,5 +1,6 @@ import { m, TargetAndTransition } from "framer-motion"; import * as React from "react"; +import { mergeRefs } from "react-merge-refs"; import useComponentSize from "~/hooks/useComponentSize"; type Props = { @@ -18,35 +19,37 @@ type Props = { /** * Automatically animates the height of a container based on it's contents. */ -export function ResizingHeightContainer(props: Props) { - const { - hideOverflow, - children, - config = { - transition: { - duration: 0.1, - ease: "easeInOut", +export const ResizingHeightContainer = React.forwardRef( + function ResizingHeightContainer_(props, forwardedRef) { + const { + hideOverflow, + children, + config = { + transition: { + duration: 0.1, + ease: "easeInOut", + }, }, - }, - style, - } = props; + style, + } = props; - const ref = React.useRef(null); - const { height } = useComponentSize(ref); + const ref = React.useRef(null); + const { height } = useComponentSize(ref); - return ( - -
{children}
-
- ); -} + return ( + +
{children}
+
+ ); + } +); diff --git a/app/scenes/Document/components/CommentThread.tsx b/app/scenes/Document/components/CommentThread.tsx index 2f602cf60d..62d6b595bf 100644 --- a/app/scenes/Document/components/CommentThread.tsx +++ b/app/scenes/Document/components/CommentThread.tsx @@ -67,6 +67,7 @@ function CommentThread({ const { editor } = useDocumentContext(); const { comments } = useStores(); const topRef = React.useRef(null); + const replyRef = React.useRef(null); const user = useCurrentUser(); const { t } = useTranslation(); const history = useHistory(); @@ -123,13 +124,13 @@ function CommentThread({ setTimeout( () => { - if (!topRef.current) { + if (!replyRef.current) { return; } - return scrollIntoView(topRef.current, { + return scrollIntoView(replyRef.current, { scrollMode: "if-needed", behavior: "smooth", - block: "end", + block: "center", boundary: (parent) => // Prevents body and other parent elements from being scrolled parent.id !== "comments", @@ -202,7 +203,7 @@ function CommentThread({ ))} - + {(focused || draft || commentsInThread.length === 0) && can.comment && (