mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
dropdown_widget: Pass current value to get_options to avoid hacky this.
This commit is contained in:
@@ -73,7 +73,7 @@ export class DropdownWidget {
|
||||
widget_selector: string;
|
||||
widget_wrapper_id: string;
|
||||
widget_value_selector: string;
|
||||
get_options: () => Option[];
|
||||
get_options: (current_value: string | number | undefined) => Option[];
|
||||
item_click_callback: (
|
||||
event: JQuery.ClickEvent,
|
||||
instance: tippy.Instance,
|
||||
@@ -200,20 +200,24 @@ export class DropdownWidget {
|
||||
"input.dropdown-list-search-input",
|
||||
);
|
||||
|
||||
this.list_widget = ListWidget.create($dropdown_list_body, this.get_options(), {
|
||||
name: `${CSS.escape(this.widget_name)}-list-widget`,
|
||||
get_item: ListWidget.default_get_item,
|
||||
modifier_html(item) {
|
||||
return render_dropdown_list({item});
|
||||
},
|
||||
filter: {
|
||||
$element: $search_input,
|
||||
predicate(item, value) {
|
||||
return item.name.toLowerCase().includes(value);
|
||||
this.list_widget = ListWidget.create(
|
||||
$dropdown_list_body,
|
||||
this.get_options(this.current_value),
|
||||
{
|
||||
name: `${CSS.escape(this.widget_name)}-list-widget`,
|
||||
get_item: ListWidget.default_get_item,
|
||||
modifier_html(item) {
|
||||
return render_dropdown_list({item});
|
||||
},
|
||||
filter: {
|
||||
$element: $search_input,
|
||||
predicate(item, value) {
|
||||
return item.name.toLowerCase().includes(value);
|
||||
},
|
||||
},
|
||||
$simplebar_container: $popper.find(".dropdown-list-wrapper"),
|
||||
},
|
||||
$simplebar_container: $popper.find(".dropdown-list-wrapper"),
|
||||
});
|
||||
);
|
||||
|
||||
$search_input.on("input.list_widget_filter", () => {
|
||||
this.show_empty_if_no_items($popper);
|
||||
@@ -371,7 +375,7 @@ export class DropdownWidget {
|
||||
this.current_value = value;
|
||||
}
|
||||
|
||||
const all_options = this.get_options();
|
||||
const all_options = this.get_options(this.current_value);
|
||||
const option = all_options.find((option) => option.unique_id === this.current_value);
|
||||
|
||||
// If provided, show custom text if cannot find current option.
|
||||
|
||||
Reference in New Issue
Block a user