Skip to content

Commit e175353

Browse files
committed
feat(chat): fix typing and scrolling in message list
1 parent 3c9f1e5 commit e175353

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

src/components/chat/chat-input.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,21 @@ export default class IgcChatInputComponent extends LitElement {
6666
this.adjustTextareaHeight();
6767
}
6868

69-
private isTyping = false;
70-
7169
private handleKeyDown(e: KeyboardEvent) {
7270
if (e.key === 'Enter' && !e.shiftKey) {
7371
e.preventDefault();
7472
this.sendMessage();
75-
} else if (this.isTyping === false) {
73+
} else {
7674
const typingEvent = new CustomEvent('typing-change', {
7775
detail: { isTyping: true },
7876
});
7977
this.dispatchEvent(typingEvent);
80-
this.isTyping = true;
8178
// wait 3 seconds and dispatch a stop-typing event
8279
setTimeout(() => {
8380
const stopTypingEvent = new CustomEvent('typing-change', {
8481
detail: { isTyping: false },
8582
});
8683
this.dispatchEvent(stopTypingEvent);
87-
this.isTyping = false;
8884
}, 3000);
8985
}
9086
}

src/components/chat/chat-message-list.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export default class IgcChatMessageListComponent extends LitElement {
9494
});
9595
}
9696

97-
protected override updated(changedProperties: Map<string, any>) {
98-
if (changedProperties.has('messages') && !this.disableAutoScroll) {
97+
protected override updated() {
98+
if (!this.disableAutoScroll) {
9999
this.scrollToBottom();
100100
}
101101
}
@@ -132,7 +132,7 @@ export default class IgcChatMessageListComponent extends LitElement {
132132
)}
133133
`
134134
)}
135-
${this.typingUsers.length > 0
135+
${this.typingUsers.filter((u) => u !== this.user).length > 0
136136
? html`
137137
<div class="typing-indicator">
138138
<div class="typing-dot"></div>

stories/chat.stories.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@ function handleTypingChange(e: CustomEvent) {
175175
const isTyping = e.detail.isTyping;
176176
const chatElements = document.querySelectorAll('igc-chat');
177177
chatElements.forEach((chat) => {
178-
if (chat.user === user) {
179-
return;
180-
}
181-
182-
if (!isTyping && chat.typingUsers.includes(user)) {
178+
if (!isTyping) {
183179
chat.typingUsers = chat.typingUsers.filter((u) => u !== user);
184180
} else if (isTyping && !chat.typingUsers.includes(user)) {
185181
chat.typingUsers = [...chat.typingUsers, user];

0 commit comments

Comments
 (0)