Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose: Correctly focus when replying to general chat.

Karl Stolley30b1ae7111f5
diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.ts
index 4c0bb0fcf92..ce486247b90 100644
--- a/web/src/compose_ui.ts
+++ b/web/src/compose_ui.ts
@@ -202,13 +202,18 @@ export function maybe_show_scrolling_formatting_buttons(container_selector: stri
function get_focus_area(opts: ComposeTriggeredOptions): string {
// Set focus to "Topic" when narrowed to a stream+topic
// and "Start new conversation" button clicked.
- if (opts.message_type === "stream" && opts.stream_id && !opts.topic) {
+ if (
+ opts.message_type === "stream" &&
+ opts.stream_id &&
+ !opts.topic &&
+ realm.realm_mandatory_topics
+ ) {
return "input#stream_message_recipient_topic";
} else if (
(opts.message_type === "stream" && opts.stream_id !== undefined) ||
(opts.message_type === "private" && opts.private_message_recipient)
) {
- if (opts.trigger === "clear topic button") {
+ if (opts.trigger === "clear topic button" || opts.trigger === "compose_hotkey") {
return "input#stream_message_recipient_topic";
}
return "textarea#compose-textarea";
diff --git a/web/tests/compose_ui.test.cjs b/web/tests/compose_ui.test.cjs
index d0a6402a458..152d85644e0 100644
--- a/web/tests/compose_ui.test.cjs
+++ b/web/tests/compose_ui.test.cjs
@@ -1280,7 +1280,7 @@ run_test("right-to-left", () => {
});
const get_focus_area = compose_ui._get_focus_area;
-run_test("get_focus_area", () => {
+run_test("get_focus_area", ({override}) => {
assert.equal(get_focus_area({message_type: "private"}), "#private_message_recipient");
assert.equal(
get_focus_area({
@@ -1293,10 +1293,16 @@ run_test("get_focus_area", () => {
get_focus_area({message_type: "stream"}),
"#compose_select_recipient_widget_wrapper",
);
+ override(realm, "realm_mandatory_topics", true);
assert.equal(
get_focus_area({message_type: "stream", stream_name: "fun", stream_id: 4}),
"input#stream_message_recipient_topic",
);
+ override(realm, "realm_mandatory_topics", false);
+ assert.equal(
+ get_focus_area({message_type: "stream", stream_name: "fun", stream_id: 4}),
+ "textarea#compose-textarea",
+ );
assert.equal(
get_focus_area({message_type: "stream", stream_name: "fun", stream_id: 4, topic: "more"}),
"textarea#compose-textarea",