Skip to content

Commit 6233057

Browse files
committed
only auto scroll if at bottom of logs
1 parent 9825d66 commit 6233057

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

web/src/components/wizard/installation/LogViewer.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef, useEffect } from 'react';
1+
import React, { useRef, useEffect, useState } from 'react';
22
import { ChevronDown, ChevronUp } from 'lucide-react';
33

44
interface LogViewerProps {
@@ -15,12 +15,24 @@ const LogViewer: React.FC<LogViewerProps> = ({
1515
onToggle
1616
}) => {
1717
const logsEndRef = useRef<HTMLDivElement>(null);
18+
const logContainerRef = useRef<HTMLDivElement>(null);
19+
const [isAtBottom, setIsAtBottom] = useState(true);
1820

21+
// Check if user is at bottom of logs
22+
const handleScroll = () => {
23+
if (!logContainerRef.current) return;
24+
25+
const { scrollTop, scrollHeight, clientHeight } = logContainerRef.current;
26+
const isBottom = Math.abs(scrollHeight - clientHeight - scrollTop) < 10;
27+
setIsAtBottom(isBottom);
28+
};
29+
30+
// Only auto-scroll if user is at bottom
1931
useEffect(() => {
20-
if (logsEndRef.current && isExpanded) {
32+
if (logsEndRef.current && isExpanded && isAtBottom) {
2133
logsEndRef.current.scrollIntoView({ behavior: 'smooth' });
2234
}
23-
}, [logs, isExpanded]);
35+
}, [logs, isExpanded, isAtBottom]);
2436

2537
return (
2638
<div className="mt-6" data-testid="log-viewer">
@@ -38,6 +50,8 @@ const LogViewer: React.FC<LogViewerProps> = ({
3850
</button>
3951
{isExpanded && (
4052
<div
53+
ref={logContainerRef}
54+
onScroll={handleScroll}
4155
className="bg-gray-900 text-gray-200 rounded-md p-4 h-48 overflow-y-auto font-mono text-xs mt-2"
4256
data-testid="log-viewer-content"
4357
>

0 commit comments

Comments
 (0)