Skip to content

Commit 9c19aa8

Browse files
committed
fix(chat): Disable chat input when sending input rather than setting the input value
1 parent f6b92d8 commit 9c19aa8

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

js/chat/chat.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ class ChatInput extends LightElement {
265265
this.#onInput();
266266
}
267267

268+
// Recheck button state when `this.disabled` updates
269+
updated(changedProperties: Map<string, unknown>) {
270+
if (changedProperties.has("disabled")) {
271+
this.#onInput();
272+
}
273+
}
274+
268275
#sendInput(): void {
269276
if (this.valueIsEmpty) return;
270277
if (this.disabled) return;
@@ -282,11 +289,11 @@ class ChatInput extends LightElement {
282289
this.setInputValue("");
283290

284291
this.textarea.focus();
292+
this.disabled = true; // Will be re-enabled by #finalizeMessage() when we get a response
285293
}
286294

287295
setInputValue(value: string): void {
288296
this.textarea.value = value;
289-
this.disabled = value.trim().length === 0;
290297

291298
// Simulate an input event (to trigger the textarea autoresize)
292299
const inputEvent = new Event("input", { bubbles: true, cancelable: true });
@@ -451,6 +458,7 @@ class ChatContainer extends LightElement {
451458
}
452459

453460
#finalizeMessage(): void {
461+
console.log("message finalized!");
454462
this.input.disabled = false;
455463
}
456464

shiny/www/py-shiny/chat/chat.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/py-shiny/chat/chat.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)