Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose_recipient: Early return in on_hidden_callback if no item click.
Prakhar Pratyush2b4d2f15f2bf
diff --git a/web/src/compose_recipient.ts b/web/src/compose_recipient.tsindex 64802751dfa..38d5b678cd1 100644--- a/web/src/compose_recipient.ts+++ b/web/src/compose_recipient.ts@@ -16,7 +16,7 @@ import type {ComposeTriggeredOptions} from "./compose_ui.ts";import * as compose_validate from "./compose_validate.ts";import * as drafts from "./drafts.ts";import * as dropdown_widget from "./dropdown_widget.ts";-import type {Option} from "./dropdown_widget.ts";+import type {DropdownWidget, Option} from "./dropdown_widget.ts";import {$t} from "./i18n.ts";import * as narrow_state from "./narrow_state.ts";import {realm} from "./state_data.ts";@@ -33,6 +33,8 @@ type DirectMessagesOption = {name: string;};+let compose_select_recipient_dropdown_widget: DropdownWidget;+function composing_to_current_topic_narrow(): boolean {return (util.lower_same(compose_state.stream_name(), narrow_state.stream_name() ?? "") &&@@ -263,6 +265,7 @@ function item_click_callback(event: JQuery.ClickEvent, dropdown: tippy.Instance)compose_state.set_selected_recipient_id(recipient_id);compose_state.set_recipient_edited_manually(true);on_compose_select_recipient_update();+ compose_select_recipient_dropdown_widget.item_clicked = true;dropdown.hide();event.preventDefault();event.stopPropagation();@@ -296,6 +299,11 @@ function focus_compose_recipient(): void {// NOTE: Since tippy triggers this on `mousedown` it is always triggered before say a `click` on `textarea`.function on_hidden_callback(): void {+ if (!compose_select_recipient_dropdown_widget.item_clicked) {+ // If the dropdown was NOT closed due to selecting an item,+ // don't do anything.+ return;+ }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@@ -308,6 +316,7 @@ function on_hidden_callback(): void {$("textarea#compose-textarea").trigger("focus");}}+ compose_select_recipient_dropdown_widget.item_clicked = false;}export function handle_middle_pane_transition(): void {@@ -317,7 +326,7 @@ export function handle_middle_pane_transition(): void {}export function initialize(): void {- new dropdown_widget.DropdownWidget({+ compose_select_recipient_dropdown_widget = new dropdown_widget.DropdownWidget({widget_name: "compose_select_recipient",get_options: get_options_for_recipient_widget,item_click_callback,@@ -331,7 +340,8 @@ export function initialize(): void {tippy_props: {offset: [-10, 5],},- }).setup();+ });+ compose_select_recipient_dropdown_widget.setup();// `input` isn't relevant for streams since it registers as a change only// when an item in the dropdown is selected.diff --git a/web/src/dropdown_widget.ts b/web/src/dropdown_widget.tsindex e0f4bd88c01..b1861b64f9d 100644--- a/web/src/dropdown_widget.ts+++ b/web/src/dropdown_widget.ts@@ -107,6 +107,10 @@ export class DropdownWidget {dropdown_input_visible_selector: string;prefer_top_start_placement: boolean;+ // TODO: This is only used in one widget, with no implementation+ // here, so should be generalized or reworked.+ item_clicked = false;+constructor(options: DropdownWidgetOptions) {this.widget_name = options.widget_name;this.widget_selector = options.widget_selector ?? `#${CSS.escape(this.widget_name)}_widget`;