typeahead: Hide by default and show container on `show()`.

This avoids a bug (currently only for search) where the page
can be loaded with an empty but visible (half-loaded) search
typeahead.
This commit is contained in:
evykassirer 2024-06-20 14:31:18 -07:00 committed by Tim Abbott
parent b519344dd9
commit 7ae0972c28
2 changed files with 48 additions and 45 deletions

View File

@ -335,11 +335,7 @@ export class Typeahead<ItemType extends string | object> {
}
this.mouse_moved_since_typeahead = false;
if (this.non_tippy_parent_element) {
this.$container.show();
// We don't need tippy to position typeaheads which already know where they should be.
return this;
}
if (!this.non_tippy_parent_element) {
this.instance = tippy.default(this.input_element.$element[0]!, {
// Lets typeahead take the width needed to fit the content
// and wraps it if it overflows the visible container.
@ -351,8 +347,9 @@ export class Typeahead<ItemType extends string | object> {
strategy: "fixed",
modifiers: [
{
// This will only work if there is enough space on the fallback placement, otherwise
// `preventOverflow` will be used to position it in the visible space.
// This will only work if there is enough space on the fallback
// placement, otherwise `preventOverflow` will be used to position
// it in the visible space.
name: "flip",
options: {
fallbackPlacements: ["top-start", "bottom-start"],
@ -361,8 +358,8 @@ export class Typeahead<ItemType extends string | object> {
{
name: "preventOverflow",
options: {
// This seems required to prevent overflow, maybe because our placements are
// not the usual top, bottom, left, right.
// This seems required to prevent overflow, maybe because our
// placements are not the usual top, bottom, left, right.
// https://popper.js.org/docs/v2/modifiers/prevent-overflow/#altaxis
altAxis: true,
},
@ -381,7 +378,12 @@ export class Typeahead<ItemType extends string | object> {
// don't want tippy to hide it for us.
hideOnClick: false,
});
}
// The container has `display: none` as a default style. We make sure to display
// it. For tippy elements, this must happen after we insert the typeahead into
// the DOM.
this.$container.show();
return this;
}

View File

@ -1,6 +1,7 @@
/* CSS for Bootstrap typeahead */
.dropdown-menu {
display: none;
padding: 5px 0;
min-width: 160px;
list-style: none;