Skip to content

Commit 7b54fb7

Browse files
fix: Composer AutoGrow causing the message list to shift (#41007)
1 parent db7dabb commit 7b54fb7

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎.changeset/famous-birds-join.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
Fixes the message list shifting when typing in the fully expanded message composer

‎apps/meteor/client/views/room/MessageList/hooks/useKeepAtBottom.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,35 @@ export const useKeepAtBottom = (isAtBottom: MutableRefObject<boolean | null>) =>
1515
const keepAtBottomRef = useSafeRefCallback(
1616
useCallback(
1717
(node: HTMLDivElement) => {
18+
const sendToBottom = () => {
19+
if (isAtBottom.current && handleRef.current) {
20+
handleRef.current();
21+
}
22+
};
1823
const listWrapper = node.firstChild;
1924
const observer = new ResizeObserver(() => {
20-
if (isAtBottom.current) {
21-
if (handleRef.current) {
22-
handleRef.current();
23-
}
24-
}
25+
sendToBottom();
2526
});
2627

2728
observer.observe(node);
2829
if (listWrapper instanceof HTMLElement) {
2930
observer.observe(listWrapper);
3031
}
3132

33+
const sendToBottomEvent = (e: Event) => {
34+
if (!(e.target instanceof HTMLElement)) return;
35+
if (!e.target.closest('.rc-message-box')) return;
36+
sendToBottom();
37+
};
38+
39+
// Workaround for height hack in useAutoGrow
40+
// node.style.height = '0';
41+
// node.style.height = `${node.scrollHeight}px`;
42+
window.addEventListener('input', sendToBottomEvent);
43+
3244
return () => {
3345
observer.disconnect();
46+
window.removeEventListener('input', sendToBottomEvent);
3447
};
3548
},
3649
[isAtBottom],

0 commit comments

Comments
 (0)