File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import { XMarkIcon } from '@heroicons/react/24/outline';
44export function Modal ( props ) {
55 const { stopHandler, navBar, children } = props ;
66 const logsEndRef = useRef ( null ) ;
7+ const scrollContainerRef = useRef ( null ) ;
8+ const isUserNearBottom = useRef ( true ) ;
79
810 useEffect ( ( ) => {
911 document . body . style . overflow = 'hidden' ;
@@ -13,9 +15,19 @@ export function Modal(props) {
1315 } , [ ] ) ;
1416
1517 useEffect ( ( ) => {
16- logsEndRef . current . scrollIntoView ( ) ;
18+ if ( isUserNearBottom . current ) {
19+ logsEndRef . current . scrollIntoView ( ) ;
20+ }
1721 } , [ children ] ) ;
1822
23+ const handleScroll = ( ) => {
24+ const container = scrollContainerRef . current ;
25+ if ( ! container ) return ;
26+ const threshold = 50 ;
27+ isUserNearBottom . current =
28+ container . scrollHeight - container . scrollTop - container . clientHeight < threshold ;
29+ } ;
30+
1931 return (
2032 < div
2133 className = "fixed flex inset-0 z-10 bg-gray-500 bg-opacity-75"
@@ -35,7 +47,7 @@ export function Modal(props) {
3547 </ button >
3648 </ div >
3749 < nav > { navBar } </ nav >
38- < div className = "h-full relative overflow-y-auto p-4 bg-slate-800 rounded-b-lg font-normal" >
50+ < div ref = { scrollContainerRef } onScroll = { handleScroll } className = "h-full relative overflow-y-auto p-4 bg-slate-800 rounded-b-lg font-normal" >
3951 { children }
4052 < p ref = { logsEndRef } />
4153 </ div >
You can’t perform that action at this time.
0 commit comments