From cf08244b6fa8d9ce3dc96a98c6a78d6da3dc9ff6 Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Thu, 13 Jun 2024 00:05:48 -0700 Subject: [PATCH] Enable keyboard navigation in the menubar --- src/IPC.js | 4 ++++ src/UI/UIWindow.js | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/IPC.js b/src/IPC.js index b0c1e0b6..aab0e7d8 100644 --- a/src/IPC.js +++ b/src/IPC.js @@ -481,6 +481,9 @@ window.addEventListener('message', async (event) => { e.preventDefault(); }); + // empty menubar + $menubar.empty(); + if(!window.menubars[event.data.appInstanceID]) window.menubars[event.data.appInstanceID] = value.items; @@ -574,6 +577,7 @@ window.addEventListener('message', async (event) => { parent_element, items: item.items, }); + $(el_window).focusWindow(e); e.stopPropagation(); e.preventDefault(); return; diff --git a/src/UI/UIWindow.js b/src/UI/UIWindow.js index 4f90c1a0..1ad4839f 100644 --- a/src/UI/UIWindow.js +++ b/src/UI/UIWindow.js @@ -2185,8 +2185,7 @@ function delete_window_element (el_window){ // resetting window counter is important so that next window opens at the center of the screen if($('.window').length === 0) window.window_counter = 0; -} - +} $(document).on('click', '.window-sidebar-item', async function(e){ const el_window = $(this).closest('.window'); @@ -3135,7 +3134,7 @@ $.fn.focusWindow = function(event) { const $app_iframe = $(this).find('.window-app-iframe'); $('.window').not(this).removeClass('window-active'); $(this).addClass('window-active'); - // disable pointer events on all other windows' iframes, except for this window's iframe + // disable pointer events on all windows' iframes, except for this window's iframe $('.window-app-iframe').not($app_iframe).css('pointer-events', 'none'); // bring this window to front, only if it's not stay_on_top if($(this).attr('data-stay_on_top') !== 'true'){ @@ -3149,9 +3148,16 @@ $.fn.focusWindow = function(event) { if($(this).attr('data-element_uuid') !== 'null'){ $(`.window[data-parent_uuid="${$(this).attr('data-element_uuid')}"]`).css('z-index', ++window.last_window_zindex); } - // - // if this has an iframe, focus on it - if(!$(this).hasClass('window-disabled') && $app_iframe.length > 0){ + + // if a menubar or any of its items are clicked, don't focus the iframe. This is important to preserve the focus on the menubar + // and to enable keyboard navigation through the menubar items + if($(event?.target).hasClass('window-menubar') || $(event?.target).closest('.window-menubar').length > 0){ + $($app_iframe).css('pointer-events', 'none'); + $app_iframe.get(0)?.blur(); + $app_iframe.get(0)?.contentWindow?.blur(); + } + // if this has an iframe + else if(!$(this).hasClass('window-disabled') && $app_iframe.length > 0){ $($app_iframe).css('pointer-events', 'all'); $app_iframe.get(0)?.focus({preventScroll:true}); $app_iframe.get(0)?.contentWindow?.focus({preventScroll:true});