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.

typeahead: Add hideOnEmptyAfterBackspace option.

Sanchit Sharmaafe9ac790072
diff --git a/web/src/bootstrap_typeahead.ts b/web/src/bootstrap_typeahead.ts
index 76f7980233e..6be42f00d6c 100644
--- a/web/src/bootstrap_typeahead.ts
+++ b/web/src/bootstrap_typeahead.ts
@@ -157,6 +157,11 @@
* This is useful for custom situations where we want to trigger the
* typeahead to do a lookup after selecting an option, when the user
* is making multiple related selections in a row.
+ *
+ * 19. Add `hideOnEmptyAfterBackspace` option, default false.
+ *
+ * This allows us to prevent the typeahead menu from being displayed
+ * when a pill is deleted using the backspace key.
* ============================================================ */
import $ from "jquery";
@@ -270,6 +275,7 @@ export class Typeahead<ItemType extends string | object> {
// Used for custom situations where we want to hide the typeahead
// after selecting an option, instead of the default call to lookup().
hideAfterSelect: () => boolean;
+ hideOnEmptyAfterBackspace: boolean;
constructor(input_element: TypeaheadInputElement, options: TypeaheadOptions<ItemType>) {
this.input_element = input_element;
@@ -310,6 +316,7 @@ export class Typeahead<ItemType extends string | object> {
this.shouldHighlightFirstResult = options.shouldHighlightFirstResult ?? (() => true);
this.updateElementContent = options.updateElementContent ?? true;
this.hideAfterSelect = options.hideAfterSelect ?? (() => true);
+ this.hideOnEmptyAfterBackspace = options.hideOnEmptyAfterBackspace ?? false;
this.listen();
}
@@ -763,6 +770,10 @@ export class Typeahead<ItemType extends string | object> {
// the search bar).
this.openInputFieldOnKeyUp();
}
+ if (pseudo_keycode === 8) {
+ this.lookup(this.hideOnEmptyAfterBackspace);
+ return;
+ }
this.lookup(false);
}
@@ -856,6 +867,7 @@ type TypeaheadOptions<ItemType> = {
dropup?: boolean;
header_html?: () => string | false;
helpOnEmptyStrings?: boolean;
+ hideOnEmptyAfterBackspace?: boolean;
matcher?: (item: ItemType, query: string) => boolean;
on_escape?: () => void;
openInputFieldOnKeyUp?: () => void;