Stay at bottom

This commit is contained in:
Bryan1029384756
2026-02-18 10:57:06 -06:00
parent e876ce5f9a
commit a9490f7bd4
2 changed files with 15 additions and 2 deletions

View File

@@ -1265,6 +1265,19 @@ const ChatArea = ({ channelId, channelName, channelType, username, channelKey, u
return () => scroller.removeEventListener('scroll', onScroll);
}, [scrollerElRef.current]);
// Keep scroll pinned to bottom when the scroll container resizes (e.g. window resize)
useEffect(() => {
const scroller = scrollerElRef.current;
if (!scroller) return;
const observer = new ResizeObserver(() => {
if (!userIsScrolledUpRef.current && !isInitialLoadRef.current) {
scroller.scrollTop = scroller.scrollHeight;
}
});
observer.observe(scroller);
return () => observer.disconnect();
}, [scrollerElRef.current]);
const saveSelection = () => {
const sel = window.getSelection();
if (sel.rangeCount > 0) savedRangeRef.current = sel.getRangeAt(0).cloneRange();