mirror of https://github.com/zulip/zulip.git
user_card_popover: Focus on menu options first when key is pressed.
As a follow-up to the commit f124ef931
, which deals with the keyboard
focus when opened via the keyboard shortcut `U`, this commit ensures
that when the user card is opened via the mouse, and the first
navigational key is pressed, the focus is on the first menu option
instead of the other tabbable elements which can be distracting.
This commit is contained in:
parent
c9667048b7
commit
4b121a8573
|
@ -90,7 +90,7 @@ class PopoverMenu {
|
|||
return;
|
||||
}
|
||||
|
||||
const $items = $("li:not(.divider):visible a:visible", $popover);
|
||||
const $items = $("[tabindex='0']", $popover).filter(":visible");
|
||||
|
||||
popover_items_handle_keyboard_with_overrides(key, $items);
|
||||
}
|
||||
|
@ -101,15 +101,21 @@ export const message_user_card = new PopoverMenu();
|
|||
export const user_card = new PopoverMenu();
|
||||
|
||||
function popover_items_handle_keyboard_with_overrides(key, $items) {
|
||||
/* Variant of popover_items_handle_keyboard */
|
||||
/* Variant of popover_items_handle_keyboard for focusing on the
|
||||
user card popover menu options first, instead of other tabbable
|
||||
buttons and links which can be distracting. */
|
||||
|
||||
if (!$items) {
|
||||
return;
|
||||
}
|
||||
|
||||
const index = $items.index($items.filter(":focus"));
|
||||
|
||||
if (key === "enter" && index >= 0 && index < $items.length) {
|
||||
$items[index].click();
|
||||
if (index === -1) {
|
||||
const first_menu_option_index = $items.index(
|
||||
$items.filter(".link-item .popover-menu-link"),
|
||||
);
|
||||
$items.eq(first_menu_option_index).trigger("focus");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue