From 6a755f37603340415cff65f2c35d0b2e9d8f50eb Mon Sep 17 00:00:00 2001
From: Arthur Sonzogni <sonzogniarthur@gmail.com>
Date: Sun, 28 Apr 2024 16:03:00 +0200
Subject: [PATCH] Fix `Menu` focus. (#850)

Bug:https://github.com/ArthurSonzogni/FTXUI/issues/841
---
 CHANGELOG.md                 | 1 +
 src/ftxui/component/menu.cpp | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9eb964f6..120dd625 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@ current (development)
 - Bugfix: Propertly restore cursor shape on exit. See #792.
 - Bugfix: Fix cursor position in when in the last column. See #831.
 - Bugfix: Fix `ResizeableSplit` keyboard navigation. Fixed by #842.
+- Bugfix: Fix `Menu` focus. See #841
 
 ### Dom
 - Feature: Add `hscroll_indicator`. It display an horizontal indicator
diff --git a/src/ftxui/component/menu.cpp b/src/ftxui/component/menu.cpp
index 21a73d89..76936364 100644
--- a/src/ftxui/component/menu.cpp
+++ b/src/ftxui/component/menu.cpp
@@ -131,8 +131,9 @@ class MenuBase : public ComponentBase, public MenuOption {
           is_focused,
       };
 
-      auto focus_management =
-          is_menu_focused && (selected_focus_ == i) ? focus : nothing;
+      auto focus_management = (selected_focus_ != i) ? nothing
+                              : is_menu_focused      ? focus
+                                                     : select;
 
       const Element element =
           (entries_option.transform ? entries_option.transform
-- 
GitLab