Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose_recipient: Improve post recipient selection behaviour.
Aman Agrawalecc1433d021e
diff --git a/web/src/compose_recipient.js b/web/src/compose_recipient.jsindex f5e2289a3ec..dbc6cf483ac 100644--- a/web/src/compose_recipient.js+++ b/web/src/compose_recipient.js@@ -202,32 +202,27 @@ export function update_compose_for_message_type(message_type, opts) {}export function on_compose_select_recipient_update() {- let message_type = "stream";+ const prev_message_type = compose_state.get_message_type();++ let curr_message_type = "stream";if (selected_recipient_id === DIRECT_MESSAGE_ID) {- message_type = "private";+ curr_message_type = "private";}- compose_state.set_message_type(message_type);- if (message_type === "private") {- // TODO: In theory, we could do something more lightweight in- // the case it's already that value, but doing nothing would- // display the wrong and fail to update focus properly.- switch_message_type("private");- if (compose_state.private_message_recipient().length === 0) {- $("#private_message_recipient").trigger("focus").trigger("select");- }- } else {+ if (prev_message_type !== curr_message_type) {+ switch_message_type(curr_message_type);+ }++ if (curr_message_type === "stream") {+ // Update stream name in the recipient box.const $stream_header_colorblock = $("#compose_recipient_selection_dropdown .stream_header_colorblock",);const stream_name = compose_state.stream_name();+ update_recipient_label(stream_name);stream_bar.decorate(stream_name, $stream_header_colorblock);- switch_message_type("stream");- // Always move focus to the topic input even if it's not empty,- // since it's likely the user will want to update the topic- // after updating the stream.- ui_util.place_caret_at_end($("#stream_message_recipient_topic")[0]);}+check_posting_policy_for_compose_box();update_on_recipient_change();}@@ -319,6 +314,22 @@ function focus_compose_recipient() {$("#compose_recipient_selection_dropdown").trigger("focus");}+// NOTE: Since tippy triggers this on `mousedown` it is always triggered before say a `click` on `textarea`.+function on_hidden_callback() {+ if (compose_state.get_message_type() === "stream") {+ // Always move focus to the topic input even if it's not empty,+ // since it's likely the user will want to update the topic+ // after updating the stream.+ ui_util.place_caret_at_end($("#stream_message_recipient_topic")[0]);+ } else {+ if (compose_state.private_message_recipient().length === 0) {+ $("#private_message_recipient").trigger("focus").trigger("select");+ } else {+ $("#compose-textarea").trigger("focus");+ }+ }+}+export function initialize() {dropdown_widget.setup({@@ -331,6 +342,7 @@ export function initialize() {on_exit_with_escape_callback: focus_compose_recipient,// We want to focus on topic box if dropdown was closed via selecting an item.focus_target_on_hidden: false,+ on_hidden_callback,},);diff --git a/web/templates/compose.hbs b/web/templates/compose.hbsindex 1c688791436..0374f94e45c 100644--- a/web/templates/compose.hbs+++ b/web/templates/compose.hbs@@ -60,7 +60,7 @@</div><div id="compose_recipient_selection_dropdown" class="new-style" tabindex="0"><div class="stream_header_colorblock"></div>- <button id="compose_select_recipient_widget" class="dropdown-widget-button" type="button">+ <button id="compose_select_recipient_widget" class="dropdown-widget-button" type="button" tabindex="-1"><span id="compose_select_recipient_name">{{t 'Select a stream'}}</span>