Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typeahead: Make helpOnEmptyStrings a callback.
Aman Agrawaleb857ccbe541
diff --git a/web/src/bootstrap_typeahead.ts b/web/src/bootstrap_typeahead.tsindex 90b11e8cd91..0b5a1e4c9e5 100644--- a/web/src/bootstrap_typeahead.ts+++ b/web/src/bootstrap_typeahead.ts@@ -243,7 +243,7 @@ export class Typeahead<ItemType extends string | object> {// Used to clear tooltip instances attached to typeahead container.clear_typeahead_tooltip: (() => void) | undefined;closeInputFieldOnHide: (() => void) | undefined;- helpOnEmptyStrings: boolean;+ helpOnEmptyStrings: () => boolean;tabIsEnter: boolean;stopAdvance: boolean;advanceKeys: string[];@@ -302,7 +302,7 @@ export class Typeahead<ItemType extends string | object> {this.advanceKeys = options.advanceKeys ?? [];this.closeInputFieldOnHide = options.closeInputFieldOnHide;this.tabIsEnter = options.tabIsEnter ?? true;- this.helpOnEmptyStrings = options.helpOnEmptyStrings ?? false;+ this.helpOnEmptyStrings = options.helpOnEmptyStrings ?? (() => false);this.non_tippy_parent_element = options.non_tippy_parent_element;this.values = new WeakMap();this.requireHighlight = options.requireHighlight ?? true;@@ -546,7 +546,7 @@ export class Typeahead<ItemType extends string | object> {// The force_lookup parameter allows specific code paths to override// the helpOnEmptyStrings configured for the typeahead element.if (- (!this.helpOnEmptyStrings || hideOnEmpty) &&+ (!this.helpOnEmptyStrings() || hideOnEmpty) &&(!this.query || this.query.length < MIN_LENGTH) &&!force_lookup) {@@ -964,7 +964,7 @@ type TypeaheadOptions<ItemType> = {closeInputFieldOnHide?: () => void;dropup?: boolean;footer_html?: (matching_items: ItemType[]) => string | false;- helpOnEmptyStrings?: boolean;+ helpOnEmptyStrings?: () => boolean;hideOnEmptyAfterBackspace?: boolean;matcher?: (query: string) => (item: ItemType) => boolean;on_escape?: () => void;diff --git a/web/src/custom_profile_fields_ui.ts b/web/src/custom_profile_fields_ui.tsindex 7be58376b2e..1ec130098bc 100644--- a/web/src/custom_profile_fields_ui.ts+++ b/web/src/custom_profile_fields_ui.ts@@ -410,7 +410,7 @@ export function initialize_custom_pronouns_type_fields(element_id: string): voidtype: "input" as const,};new Typeahead(bootstrap_typeahead_input, {- helpOnEmptyStrings: true,+ helpOnEmptyStrings: () => true,source() {return commonly_used_pronouns;},diff --git a/web/src/pill_typeahead.ts b/web/src/pill_typeahead.tsindex d9fbdc70d26..dacd26f4a60 100644--- a/web/src/pill_typeahead.ts+++ b/web/src/pill_typeahead.ts@@ -96,11 +96,10 @@ export function set_up_stream($element: $input,type: "contenteditable",};- opts.help_on_empty_strings ??= false;opts.hide_on_empty_after_backspace ??= false;new Typeahead(bootstrap_typeahead_input, {dropup: true,- helpOnEmptyStrings: opts.help_on_empty_strings,+ helpOnEmptyStrings: () => opts.help_on_empty_strings ?? false,hideOnEmptyAfterBackspace: opts.hide_on_empty_after_backspace,source(_query: string): StreamPillData[] {return stream_pill.typeahead_source(pills, opts.invite_streams);@@ -174,7 +173,7 @@ export function set_up_user_group($input.trigger("focus");},stopAdvance: true,- helpOnEmptyStrings: true,+ helpOnEmptyStrings: () => true,hideOnEmptyAfterBackspace: true,});}@@ -263,7 +262,7 @@ export function set_up_group_setting_typeahead($input.trigger("focus");},stopAdvance: true,- helpOnEmptyStrings: true,+ helpOnEmptyStrings: () => true,hideOnEmptyAfterBackspace: true,});}@@ -298,7 +297,7 @@ export function set_up_combined(};new Typeahead(bootstrap_typeahead_input, {dropup: true,- helpOnEmptyStrings: true,+ helpOnEmptyStrings: () => true,hideOnEmptyAfterBackspace: true,source(query: string): TypeaheadItem[] {let source: TypeaheadItem[] = [];diff --git a/web/src/search.ts b/web/src/search.tsindex 1484b99e7ae..45acecdbf92 100644--- a/web/src/search.ts+++ b/web/src/search.ts@@ -212,7 +212,7 @@ export function initialize(opts: {on_narrow_search: OnNarrowSearch}): void {},non_tippy_parent_element: "#searchbox_form",items: search_suggestion.max_num_of_search_results,- helpOnEmptyStrings: true,+ helpOnEmptyStrings: () => true,stopAdvance: true,requireHighlight: false,item_html(query: string): (item: string) => string {diff --git a/web/src/settings_playgrounds.ts b/web/src/settings_playgrounds.tsindex eac24f6336a..678fa41da7e 100644--- a/web/src/settings_playgrounds.ts+++ b/web/src/settings_playgrounds.ts@@ -164,7 +164,7 @@ function build_page(): void {language_labels = realm_playground.get_pygments_typeahead_list_for_settings(query);return [...language_labels.keys()];},- helpOnEmptyStrings: true,+ helpOnEmptyStrings: () => true,item_html(_query: string): (item: string) => string {return (item: string) => render_typeahead_item({primary: language_labels.get(item)});},diff --git a/web/tests/pill_typeahead.test.cjs b/web/tests/pill_typeahead.test.cjsindex 48130cfc778..6b6435aab12 100644--- a/web/tests/pill_typeahead.test.cjs+++ b/web/tests/pill_typeahead.test.cjs@@ -283,6 +283,7 @@ run_test("set_up_stream", ({mock_template, override, override_rewire}) => {assert.equal(typeof config.matcher, "function");assert.equal(typeof config.sorter, "function");assert.equal(typeof config.updater, "function");+ assert.equal(config.helpOnEmptyStrings(), false);// test queriesconst stream_query = "#denmark";@@ -376,6 +377,7 @@ run_test("set_up_user_group", ({mock_template, override, override_rewire}) => {assert.equal(typeof config.matcher, "function");assert.equal(typeof config.sorter, "function");assert.equal(typeof config.updater, "function");+ assert.equal(config.helpOnEmptyStrings(), true);const group_query = "testers";@@ -476,6 +478,7 @@ run_test("set_up_combined", ({mock_template, override, override_rewire}) => {assert.equal(typeof config.matcher, "function");assert.equal(typeof config.sorter, "function");assert.equal(typeof config.updater, "function");+ assert.equal(config.helpOnEmptyStrings(), true);// test queriesconst stream_query = "#Denmark";@@ -786,6 +789,7 @@ run_test("set_up_group_setting_typeahead", ({mock_template, override, override_rassert.equal(typeof config.matcher, "function");assert.equal(typeof config.sorter, "function");assert.equal(typeof config.updater, "function");+ assert.equal(config.helpOnEmptyStrings(), true);// test queriesconst person_query = "me";diff --git a/web/tests/search.test.cjs b/web/tests/search.test.cjsindex 5fd1374fdea..2077e72838a 100644--- a/web/tests/search.test.cjs+++ b/web/tests/search.test.cjs@@ -82,7 +82,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {opts = opts_;assert.equal(input_element.$element[0], $search_query_box[0]);assert.equal(opts.items, 999);- assert.equal(opts.helpOnEmptyStrings, true);+ assert.equal(opts.helpOnEmptyStrings(), true);assert.equal(opts.matcher("")(), true);search_typeahead = {