user_groups: Open group setting typeahead on clicking label.

Fixes #32007.
This commit is contained in:
Shubham Padia 2024-10-16 07:14:41 +00:00 committed by Tim Abbott
parent 5980f4a502
commit 4a2f126af9
3 changed files with 20 additions and 0 deletions

View File

@ -1417,6 +1417,21 @@ export function initialize_disable_btn_hint_popover(
tippy.default(util.the($btn_wrapper), tippy_opts);
}
export function enable_opening_typeahead_on_clicking_label($container: JQuery): void {
const $group_setting_labels = $container.find(".group-setting-label");
$group_setting_labels.on("click", (e) => {
// Click opens the typeahead.
$(e.target).siblings(".pill-container").find(".input").expectOne().trigger("click");
// Focus puts the cursor into the input.
$(e.target).siblings(".pill-container").find(".input").expectOne().trigger("focus");
});
}
export function disable_opening_typeahead_on_clicking_label($container: JQuery): void {
const $group_setting_labels = $container.find(".group-setting-label");
$group_setting_labels.off("click");
}
export const group_setting_widget_map = new Map<string, GroupSettingPillContainer | null>([
["can_add_members_group", null],
["can_join_group", null],

View File

@ -253,6 +253,9 @@ export function set_up_handlers(): void {
}
});
// This will always be enabled when creating a user group.
settings_components.enable_opening_typeahead_on_clicking_label($container);
can_add_members_group_widget = settings_components.create_group_setting_widget({
$pill_container: $container.find(".can-add-members-group-container .pill-container"),
setting_name: "can_add_members_group",

View File

@ -121,6 +121,7 @@ function update_group_permission_settings_elements(group) {
$permission_pill_container_elements.each(function () {
$(this)[0]._tippy?.destroy();
});
settings_components.enable_opening_typeahead_on_clicking_label($group_permission_settings);
} else {
$permission_pill_container_elements.find(".input").prop("contenteditable", false);
@ -132,6 +133,7 @@ function update_group_permission_settings_elements(group) {
$t({defaultMessage: "You do not have permission to edit this setting."}),
);
});
settings_components.disable_opening_typeahead_on_clicking_label($group_permission_settings);
}
}