Skip to content

Commit 7a45f3a

Browse files
committed
fix: fix test auto scroll
1 parent 6e3118c commit 7a45f3a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/commons/data-display/List/testgroup.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from "react";
1+
import { useEffect, useState, useRef } from "react";
22
import { motion } from "framer-motion";
33
import ServerItem from "./serveritem";
44

@@ -16,6 +16,12 @@ const chatContents = [
1616
export default function TestChatList({ onFinish }: { onFinish?: () => void }) {
1717
const [visibleCount, setVisibleCount] = useState(0);
1818

19+
const bottomRef = useRef<HTMLDivElement | null>(null);
20+
21+
useEffect(() => {
22+
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
23+
}, [visibleCount]);
24+
1925
useEffect(() => {
2026
if (visibleCount < chatContents.length) {
2127
const timer = setTimeout(() => {
@@ -40,6 +46,7 @@ export default function TestChatList({ onFinish }: { onFinish?: () => void }) {
4046
<ServerItem contents={contents} />
4147
</motion.div>
4248
))}
49+
<div ref={bottomRef} />
4350
</div>
4451
);
4552
}

src/services/home/chat/TestSection/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from "react";
1+
import { useState, useEffect, useRef } from "react";
22
import UmAvatar from "../../../../commons/data-display/Avatar";
33
import TestChatList from "../../../../commons/data-display/List/testgroup";
44
import TestToggle from "../TestToggle";
@@ -8,6 +8,11 @@ const TestSection = () => {
88
const [isListFinished, setIsListFinished] = useState(false);
99
const selectedTest = useChatStore((state) => state.suggestedTest || "phq-9");
1010
const setSelectedTest = useChatStore((state) => state.setSuggestedTest);
11+
const bottomRef = useRef<HTMLDivElement | null>(null);
12+
13+
useEffect(() => {
14+
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
15+
}, [isListFinished]);
1116

1217
useEffect(() => {
1318
setSelectedTest("");
@@ -29,6 +34,7 @@ const TestSection = () => {
2934
<TestToggle selected={selectedTest} onSelect={setSelectedTest} />
3035
</div>
3136
)}
37+
<div ref={bottomRef} />
3238
</div>
3339
</div>
3440
);

0 commit comments

Comments
 (0)