popovers: Enable keyboard support for user info popovers.

This commit enables keyboard support for user info popovers for
navigating through popover options using up/down keys.

We add get_user_info_popover_items function, whose implementation
is different from other similar functions. Instead of using
popover_data.$tip we directly use $("div.user-info-popover")
because when we open the popover of bot owner from the bot
popover, the element which opens the popover is removed from
DOM and popover_data is undefined.
This commit is contained in:
sahil839 2020-09-22 22:49:40 +05:30 committed by Tim Abbott
parent 7525642507
commit 4dc3e5f96f
3 changed files with 32 additions and 1 deletions

View File

@ -210,6 +210,7 @@ run_test("basic_chars", () => {
actions_popped: return_false, actions_popped: return_false,
message_info_popped: return_false, message_info_popped: return_false,
user_sidebar_popped: return_false, user_sidebar_popped: return_false,
user_info_popped: return_false,
}); });
set_global("stream_popover", { set_global("stream_popover", {
stream_popped: return_false, stream_popped: return_false,

View File

@ -306,6 +306,11 @@ exports.process_enter_key = function (e) {
return true; return true;
} }
if (popovers.user_info_popped()) {
popovers.user_info_popover_handle_keyboard("enter");
return true;
}
if (stream_popover.stream_popped()) { if (stream_popover.stream_popped()) {
stream_popover.stream_sidebar_menu_handle_keyboard("enter"); stream_popover.stream_sidebar_menu_handle_keyboard("enter");
return true; return true;
@ -524,7 +529,7 @@ exports.process_hotkey = function (e, hotkey) {
return false; return false;
} }
if (overlays.settings_open()) { if (overlays.settings_open() && !popovers.user_info_popped()) {
return false; return false;
} }
@ -579,6 +584,11 @@ exports.process_hotkey = function (e, hotkey) {
return true; return true;
} }
if (popovers.user_info_popped()) {
popovers.user_info_popover_handle_keyboard(event_name);
return true;
}
if (popovers.user_sidebar_popped()) { if (popovers.user_sidebar_popped()) {
popovers.user_sidebar_popover_handle_keyboard(event_name); popovers.user_sidebar_popover_handle_keyboard(event_name);
return true; return true;

View File

@ -388,6 +388,21 @@ function get_user_info_popover_for_message_items() {
return $("li:not(.divider):visible a", popover_data.$tip); return $("li:not(.divider):visible a", popover_data.$tip);
} }
function get_user_info_popover_items() {
const popover_elt = $("div.user-info-popover");
if (!current_user_info_popover_elem || !popover_elt.length) {
blueslip.error("Trying to get menu items when action popover is closed.");
return;
}
if (popover_elt.length >= 2) {
blueslip.error("More than one user info popovers cannot be opened at same time.");
return;
}
return $("li:not(.divider):visible a", popover_elt);
}
function fetch_group_members(member_ids) { function fetch_group_members(member_ids) {
return member_ids return member_ids
.map((m) => people.get_by_user_id(m)) .map((m) => people.get_by_user_id(m))
@ -745,6 +760,11 @@ exports.user_info_popover_for_message_handle_keyboard = function (key) {
exports.popover_items_handle_keyboard(key, items); exports.popover_items_handle_keyboard(key, items);
}; };
exports.user_info_popover_handle_keyboard = function (key) {
const items = get_user_info_popover_items();
exports.popover_items_handle_keyboard(key, items);
};
exports.show_sender_info = function () { exports.show_sender_info = function () {
const $message = $(".selected_message"); const $message = $(".selected_message");
const $sender = $message.find(".sender_info_hover"); const $sender = $message.find(".sender_info_hover");