From b3347e1b6788271216016f40d9a7c11e32f3fde7 Mon Sep 17 00:00:00 2001
From: Behrokh Satarnejad <b.satarnejad@openproject.com>
Date: Tue, 5 Nov 2024 09:24:40 +0100
Subject: [PATCH] set focus on first element of menu

---
 .../src/app/core/main-menu/main-menu-toggle.service.ts     | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/frontend/src/app/core/main-menu/main-menu-toggle.service.ts b/frontend/src/app/core/main-menu/main-menu-toggle.service.ts
index 168344aa9a61..a8b110fdf35d 100644
--- a/frontend/src/app/core/main-menu/main-menu-toggle.service.ts
+++ b/frontend/src/app/core/main-menu/main-menu-toggle.service.ts
@@ -132,9 +132,14 @@ export class MainMenuToggleService {
     } else {
       this.openMenu();
     }
-
     // Save the collapsed state in localStorage
     window.OpenProject.guardedLocalStorage(this.localStorageStateKey, String(!this.showNavigation));
+    // Set focus on first visible main menu item.
+    // This needs to be called after AngularJS has rendered the menu, which happens some when after(!) we leave this
+    // method here. So we need to set the focus after a timeout.
+    setTimeout(() => {
+      jQuery('#main-menu [class*="-menu-item"]:visible').first().focus();
+    }, 500);
   }
 
   public closeMenu():void {