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: Fix typeahead position not updating on pill remove.

adnan-td54be4443aebf
diff --git a/web/src/bootstrap_typeahead.ts b/web/src/bootstrap_typeahead.ts
index 56637cb2ab9..9800b4fdba6 100644
--- a/web/src/bootstrap_typeahead.ts
+++ b/web/src/bootstrap_typeahead.ts
@@ -505,7 +505,8 @@ export class Typeahead<ItemType extends string | object> {
.on("keypress", this.keypress.bind(this))
.on("keyup", this.keyup.bind(this))
.on("click", this.element_click.bind(this))
- .on("keydown", this.keydown.bind(this));
+ .on("keydown", this.keydown.bind(this))
+ .on("typeahead.refreshPosition", this.refreshPosition.bind(this));
this.$menu
.on("click", "li", this.click.bind(this))
@@ -736,6 +737,14 @@ export class Typeahead<ItemType extends string | object> {
this.$menu.find(".active").removeClass("active");
$(e.currentTarget).addClass("active");
}
+
+ refreshPosition(e: JQuery.Event): void {
+ e.stopPropagation();
+ // Refresh the typeahead menu to account for any changes in the
+ // input position by asking popper to recompute your tooltip's position.
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
+ this.instance?.popperInstance?.update();
+ }
}
/* TYPEAHEAD PLUGIN DEFINITION
diff --git a/web/src/input_pill.ts b/web/src/input_pill.ts
index ed1db39bb60..e8544e5634a 100644
--- a/web/src/input_pill.ts
+++ b/web/src/input_pill.ts
@@ -440,6 +440,9 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
const $next = $pill.next();
funcs.removePill($pill[0]!);
+ // Since removing a pill moves the $input, typeahead needs to refresh
+ // to appear at the correct position.
+ store.$input.trigger(new $.Event("typeahead.refreshPosition"));
$next.trigger("focus");
});