From ae65b253c448cb29f7cf5ee87b039603dcf49513 Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 8 Mar 2024 15:22:23 +0800 Subject: [PATCH] fix: copyright Signed-off-by: Innei --- .../comment/CommentBox/UniversalTextArea.tsx | 21 ++++++++++++------- src/components/modules/post/PostCopyright.tsx | 7 ++++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/components/modules/comment/CommentBox/UniversalTextArea.tsx b/src/components/modules/comment/CommentBox/UniversalTextArea.tsx index 95eedcc713..b9902b04a5 100644 --- a/src/components/modules/comment/CommentBox/UniversalTextArea.tsx +++ b/src/components/modules/comment/CommentBox/UniversalTextArea.tsx @@ -1,6 +1,7 @@ 'use client' import { useCallback, useEffect, useRef } from 'react' +import { useIsomorphicLayoutEffect } from 'foxact/use-isomorphic-layout-effect' import dynamic from 'next/dynamic' import { FloatPopover } from '~/components/ui/float-popover' @@ -53,13 +54,19 @@ export const UniversalTextArea: Component = ({ className }) => { } }, [value]) - // useLayoutEffect(() => { - // // autofocus - // const $ta = taRef.current - // if (!$ta) return - // $ta.selectionStart = $ta.selectionEnd = $ta.value.length - // $ta.focus() - // }, []) + useIsomorphicLayoutEffect(() => { + if (location.hash !== '#comment') { + return + } + + // autofocus + const $ta = taRef.current + if (!$ta) return + $ta.selectionStart = $ta.selectionEnd = $ta.value.length + $ta.focus() + + $ta.scrollIntoView({ behavior: 'smooth', block: 'center' }) + }, []) return (