Skip to content

Commit

Permalink
fix(chat): Disable chat input when sending input rather than setting …
Browse files Browse the repository at this point in the history
…the input value
  • Loading branch information
gadenbuie committed Nov 21, 2024
1 parent f6b92d8 commit 9c19aa8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion js/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ class ChatInput extends LightElement {
this.#onInput();
}

// Recheck button state when `this.disabled` updates
updated(changedProperties: Map<string, unknown>) {
if (changedProperties.has("disabled")) {
this.#onInput();
}
}

#sendInput(): void {
if (this.valueIsEmpty) return;
if (this.disabled) return;
Expand All @@ -282,11 +289,11 @@ class ChatInput extends LightElement {
this.setInputValue("");

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

setInputValue(value: string): void {
this.textarea.value = value;
this.disabled = value.trim().length === 0;

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

#finalizeMessage(): void {
console.log("message finalized!");
this.input.disabled = false;
}

Expand Down
2 changes: 1 addition & 1 deletion shiny/www/py-shiny/chat/chat.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions shiny/www/py-shiny/chat/chat.js.map

Large diffs are not rendered by default.

0 comments on commit 9c19aa8

Please sign in to comment.