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.

dropdowns: Add threshold to hide search box for short lists.

yaswanth1723220b19c98b58
diff --git a/web/src/dropdown_widget.ts b/web/src/dropdown_widget.ts
index e776de23547..0696af1b2f2 100644
--- a/web/src/dropdown_widget.ts
+++ b/web/src/dropdown_widget.ts
@@ -19,6 +19,8 @@ import * as util from "./util.ts";
/* Sync with max-height set in zulip.css */
export const DEFAULT_DROPDOWN_HEIGHT = 210;
+/* Default minimum items required to show the search box. */
+export const MIN_ITEMS_TO_SHOW_SEARCH_BOX = 3;
const noop = (): void => {
// Empty function for default values.
};
@@ -77,6 +79,7 @@ export type DropdownWidgetOptions = {
// Text to show if the current value is not in `get_options()`.
text_if_current_value_not_in_options?: string;
hide_search_box?: boolean;
+ min_items_to_show_search_box?: number;
// Disable the widget for spectators.
disable_for_spectators?: boolean;
dropdown_input_visible_selector?: string;
@@ -117,7 +120,12 @@ export class DropdownWidget {
unique_id_type: DataType | undefined;
$events_container: JQuery;
text_if_current_value_not_in_options: string;
+ // Effective value used while dropdown is open.
hide_search_box: boolean;
+ // Remember caller’s explicit request to hide search.
+ initial_hide_search_box: boolean;
+ // Only show the search box if options.length > threshold.
+ min_items_to_show_search_box: number;
disable_for_spectators: boolean;
dropdown_input_visible_selector: string;
prefer_top_start_placement: boolean;
@@ -157,6 +165,11 @@ export class DropdownWidget {
this.text_if_current_value_not_in_options =
options.text_if_current_value_not_in_options ?? "";
this.hide_search_box = options.hide_search_box ?? false;
+ // Preserve caller's original request to hide the search box.
+ this.initial_hide_search_box = options.hide_search_box ?? false;
+ // Use constant default if the caller didn't provide a value.
+ this.min_items_to_show_search_box =
+ options.min_items_to_show_search_box ?? MIN_ITEMS_TO_SHOW_SEARCH_BOX;
this.disable_for_spectators = options.disable_for_spectators ?? false;
this.dropdown_input_visible_selector =
options.dropdown_input_visible_selector ?? this.widget_selector;
@@ -327,6 +340,12 @@ export class DropdownWidget {
// mobile.
$(instance.popper).find(".tippy-box").addClass("show-when-reference-hidden");
}
+ // Automatically hide the search box for short lists,
+ // unless the caller explicitly requested to hide it.
+ if (!this.initial_hide_search_box) {
+ const options = this.get_options(this.current_value);
+ this.hide_search_box = options.length <= this.min_items_to_show_search_box;
+ }
instance.setContent(
parse_html(
render_dropdown_list_container({