dropdown_widget: Show empty list text without initiating search.

Fixes #26649

If there are no items for dropdown widget to display, show empty
search result text.
This commit is contained in:
Aman Agrawal 2023-09-07 04:10:37 +00:00 committed by Tim Abbott
parent 656494d73b
commit 6321ab54ce
2 changed files with 13 additions and 8 deletions

View File

@ -86,6 +86,16 @@ export class DropdownWidget {
);
}
show_empty_if_no_items($popper) {
const list_items = this.list_widget.get_current_list();
const $no_search_results = $popper.find(".no-dropdown-items");
if (list_items.length === 0) {
$no_search_results.show();
} else {
$no_search_results.hide();
}
}
setup() {
this.init();
const delegate_container = this.$events_container.get(0);
@ -123,13 +133,7 @@ export class DropdownWidget {
});
$search_input.on("input.list_widget_filter", () => {
const list_items = this.list_widget.get_current_list();
const $no_search_results = $popper.find(".no-dropdown-items");
if (list_items.length === 0) {
$no_search_results.show();
} else {
$no_search_results.hide();
}
this.show_empty_if_no_items($popper);
});
// Keyboard handler
@ -232,6 +236,7 @@ export class DropdownWidget {
this.on_show_callback(instance);
}.bind(this),
onMount: function (instance) {
this.show_empty_if_no_items($(instance.popper));
this.on_mount_callback(instance);
}.bind(this),
onHidden: function (instance) {

View File

@ -6,6 +6,6 @@
<ul class="dropdown-list"></ul>
</div>
<div class="no-dropdown-items dropdown-list-item-common-styles">
{{t 'No search results'}}
{{t 'No matching results'}}
</div>
</div>