user_card_popover: Fix keyboard navigation opening manage menu.

`focus_first_popover_item` was executed right after the click handler
 had asked to open the popover, but before the popover was mounted to
 the DOM, causing the popover to not work correctly when opened via
 the keyboard.
This commit is contained in:
Daniil Fadeev 2023-09-19 18:30:40 +03:00 committed by Tim Abbott
parent 0ab788c9c9
commit bb58fecf28
1 changed files with 22 additions and 2 deletions

View File

@ -58,8 +58,28 @@ export function popover_items_handle_keyboard(key, $items) {
if (key === "enter" && index >= 0 && index < $items.length) { if (key === "enter" && index >= 0 && index < $items.length) {
$items[index].click(); $items[index].click();
if (user_card_popover.manage_menu.is_open()) { if (user_card_popover.manage_menu.is_open()) {
// If we just opened the little manage menu via the
// keyboard, we need to focus the first item for a
// continuation of the keyboard experience.
// TODO: This might be cleaner to just call
// toggle_user_card_popover_manage_menu rather than
// triggering a click.
const previously_defined_on_mount =
user_card_popover.manage_menu.instance.props.onMount;
user_card_popover.manage_menu.instance.setProps({
onMount() {
// We're monkey patching the onMount method here to ensure we start
// focusing on the item after the popover is mounted to the DOM;
// otherwise, it won't work correctly.
if (previously_defined_on_mount) {
previously_defined_on_mount();
}
const $items = user_card_popover.get_user_card_popover_manage_menu_items(); const $items = user_card_popover.get_user_card_popover_manage_menu_items();
focus_first_popover_item($items); focus_first_popover_item($items);
},
});
} }
return; return;
} }