typeahead: Fix typeahead position not updating on pill remove.

Calls popper instance update method to refresh the position
of the typeahead menu.
This commit is contained in:
adnan-td
2024-07-06 14:47:02 +05:30
committed by Tim Abbott
parent ddfc2d230f
commit 54be4443ae
2 changed files with 13 additions and 1 deletions

View File

@@ -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

View File

@@ -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");
});