Skip to content

Commit c964ee6

Browse files
r-farkhutdinovRuslan FarkhutdinovCopilot
authored
Chat: Fix MessageList auto-scroll on multiple message push (#33637)
Signed-off-by: Ruslan Farkhutdinov <rrafarkhutdinov@gmail.com> Co-authored-by: Ruslan Farkhutdinov <ruslan.farkhutdinov@devexpress.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 74714d8 commit c964ee6

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

packages/devextreme/js/__internal/ui/chat/messagelist.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,15 @@ class MessageList extends Widget<Properties> {
769769
}
770770

771771
_setIsReachedBottom(): void {
772-
this._isBottomReached = !this._isContentOverflowing() || this._scrollView.isBottomReached();
772+
if (!this._isContentOverflowing()) {
773+
this._isBottomReached = true;
774+
775+
return;
776+
}
777+
778+
const container = this._scrollableContainer();
779+
const maxScroll = getScrollTopMax(container);
780+
this._isBottomReached = Math.round(maxScroll - Math.ceil(container.scrollTop)) <= 1;
773781
}
774782

775783
_isContentOverflowing(): boolean {

packages/devextreme/testing/tests/DevExpress.ui.widgets/chatParts/messageList.tests.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,44 @@ QUnit.module('MessageList', () => {
18691869
}, this._resizeTimeout);
18701870
}, this._resizeTimeout);
18711871
});
1872+
1873+
QUnit.test('should be scrolled down to companion reply rendered immediately after current user message', function(assert) {
1874+
const done = assert.async();
1875+
const items = generateMessages(67);
1876+
1877+
this.reinit({
1878+
width: 300,
1879+
height: 500,
1880+
items,
1881+
currentUserId: MOCK_CURRENT_USER_ID,
1882+
});
1883+
1884+
const userMessage = {
1885+
author: { id: MOCK_CURRENT_USER_ID },
1886+
timestamp: NOW,
1887+
text: 'User message',
1888+
};
1889+
1890+
const replyMessage = {
1891+
author: { id: MOCK_COMPANION_USER_ID },
1892+
timestamp: NOW,
1893+
text: 'Reply',
1894+
};
1895+
1896+
setTimeout(() => {
1897+
const scrollTopBefore = this.getScrollView().scrollTop();
1898+
assert.roughEqual(scrollTopBefore, this.getScrollOffsetMax(), 1, 'scroll position should be at the bottom before test');
1899+
1900+
this.instance.option('items', [...items, userMessage]);
1901+
this.instance.option('items', [...items, userMessage, replyMessage]);
1902+
1903+
setTimeout(() => {
1904+
const scrollTop = this.getScrollView().scrollTop();
1905+
assert.roughEqual(scrollTop, this.getScrollOffsetMax(), 1, 'scroll position should be at the bottom after the companion reply');
1906+
done();
1907+
});
1908+
}, this._resizeTimeout);
1909+
});
18721910
});
18731911

18741912
QUnit.module('localization', moduleConfig, () => {

0 commit comments

Comments
 (0)