Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 5ec6a99

Browse files
committed
UX: focus conversation input on route transition and button click
1 parent cab3983 commit 5ec6a99

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

assets/javascripts/discourse/components/ai-bot-conversations.gjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { on } from "@ember/modifier";
55
import { action } from "@ember/object";
66
import { getOwner } from "@ember/owner";
77
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
8+
import { scheduleOnce } from "@ember/runloop";
89
import { service } from "@ember/service";
910
import { TrackedArray } from "@ember-compat/tracked-built-ins";
1011
import $ from "jquery";
@@ -163,6 +164,12 @@ export default class AiBotConversations extends Component {
163164
setTextArea(element) {
164165
this.textarea = element;
165166
this.setupAutocomplete(element);
167+
scheduleOnce("afterRender", this, this.focusTextarea);
168+
}
169+
170+
@action
171+
focusTextarea() {
172+
this.textarea?.focus();
166173
}
167174

168175
@action
@@ -198,7 +205,7 @@ export default class AiBotConversations extends Component {
198205
transformComplete: (obj) => obj.username || obj.name,
199206
afterComplete: (text) => {
200207
this.textarea.value = text;
201-
this.textarea.focus();
208+
this.focusTextarea();
202209
this.updateInputValue({ target: { value: text } });
203210
},
204211
onClose: destroyUserStatuses,
@@ -215,7 +222,7 @@ export default class AiBotConversations extends Component {
215222
treatAsTextarea: true,
216223
afterComplete: (text) => {
217224
this.textarea.value = text;
218-
this.textarea.focus();
225+
this.focusTextarea();
219226
this.updateInputValue({ target: { value: text } });
220227
},
221228
});

assets/javascripts/discourse/components/ai-bot-sidebar-new-conversation.gjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ export default class AiBotSidebarNewConversation extends Component {
1313
return this.sidebarState.isCurrentPanel(AI_CONVERSATIONS_PANEL);
1414
}
1515

16+
@action
17+
focusTextarea() {
18+
document.getElementById("ai-bot-conversations-input")?.focus();
19+
}
20+
1621
@action
1722
routeTo() {
1823
this.appEvents.trigger("discourse-ai:new-conversation-btn-clicked");
1924

2025
if (this.router.currentRouteName !== "discourse-ai-bot-conversations") {
2126
this.router.transitionTo("/discourse-ai/ai-bot/conversations");
27+
} else {
28+
this.focusTextarea();
2229
}
30+
2331
this.args.outletArgs?.toggleNavigationMenu?.();
2432
}
2533

0 commit comments

Comments
 (0)