Stay at bottom
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user