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

Commit 24416c5

Browse files
authored
UX: focus conversation input on route transition and button click (#1404)
1 parent b5e8277 commit 24416c5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-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";
@@ -164,6 +165,12 @@ export default class AiBotConversations extends Component {
164165
setTextArea(element) {
165166
this.textarea = element;
166167
this.setupAutocomplete(element);
168+
scheduleOnce("afterRender", this, this.focusTextarea);
169+
}
170+
171+
@action
172+
focusTextarea() {
173+
this.textarea?.focus();
167174
}
168175

169176
@action
@@ -199,7 +206,7 @@ export default class AiBotConversations extends Component {
199206
transformComplete: (obj) => obj.username || obj.name,
200207
afterComplete: (text) => {
201208
this.textarea.value = text;
202-
this.textarea.focus();
209+
this.focusTextarea();
203210
this.updateInputValue({ target: { value: text } });
204211
},
205212
onClose: destroyUserStatuses,
@@ -216,7 +223,7 @@ export default class AiBotConversations extends Component {
216223
treatAsTextarea: true,
217224
afterComplete: (text) => {
218225
this.textarea.value = text;
219-
this.textarea.focus();
226+
this.focusTextarea();
220227
this.updateInputValue({ target: { value: text } });
221228
},
222229
});

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { service } from "@ember/service";
44
import DButton from "discourse/components/d-button";
55
import { AI_CONVERSATIONS_PANEL } from "../services/ai-conversations-sidebar-manager";
66

7+
const TEXTAREA_ID = "ai-bot-conversations-input";
8+
79
export default class AiBotSidebarNewConversation extends Component {
810
@service appEvents;
911
@service router;
@@ -13,13 +15,21 @@ export default class AiBotSidebarNewConversation extends Component {
1315
return this.sidebarState.isCurrentPanel(AI_CONVERSATIONS_PANEL);
1416
}
1517

18+
@action
19+
focusTextarea() {
20+
document.getElementById(TEXTAREA_ID)?.focus();
21+
}
22+
1623
@action
1724
routeTo() {
1825
this.appEvents.trigger("discourse-ai:new-conversation-btn-clicked");
1926

2027
if (this.router.currentRouteName !== "discourse-ai-bot-conversations") {
2128
this.router.transitionTo("/discourse-ai/ai-bot/conversations");
29+
} else {
30+
this.focusTextarea();
2231
}
32+
2333
this.args.outletArgs?.toggleNavigationMenu?.();
2434
}
2535

0 commit comments

Comments
 (0)