Skip to content

Commit 8a8335a

Browse files
committed
fix(chat-messages): store current scroll height
1 parent 22fb04c commit 8a8335a

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

projects/element-ng/chat-messages/si-chat-container.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class SiChatContainerComponent implements AfterContentInit, OnDestroy {
5555
private scrollDebounceMs = 7; // ~144fps
5656
private resizeObserver: ResizeObserver | undefined;
5757
private contentObserver: MutationObserver | undefined;
58+
private lastScrollHeight = 0;
5859

5960
/**
6061
* The color variant to apply to the container.
@@ -145,9 +146,15 @@ export class SiChatContainerComponent implements AfterContentInit, OnDestroy {
145146
}
146147

147148
this.resizeObserver = new ResizeObserver(() => {
148-
this.debouncedScrollToBottom();
149+
const element = container.nativeElement;
150+
const currentScrollHeight = element.scrollHeight;
151+
if (currentScrollHeight > this.lastScrollHeight) {
152+
this.debouncedScrollToBottom();
153+
}
154+
this.lastScrollHeight = currentScrollHeight;
149155
});
150156

157+
this.lastScrollHeight = container.nativeElement.scrollHeight;
151158
this.resizeObserver.observe(container.nativeElement);
152159
}
153160

src/app/examples/si-chat-messages/si-chat-container.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="si-layout-fixed-height w-100 h-100">
2-
<si-chat-container #chatContainer colorVariant="base-0" noAutoScroll>
2+
<si-chat-container #chatContainer colorVariant="base-0">
33
@for (message of messages(); track message) {
44
@if (message.type === 'user') {
55
<si-user-message

0 commit comments

Comments
 (0)