From 20baaef5b8b9127916d8a853305e2b757bcc290c Mon Sep 17 00:00:00 2001
From: mingsheng13 <102264706+mingsheng13@users.noreply.github.com>
Date: Sat, 19 Aug 2023 11:02:04 +0100
Subject: [PATCH] Dropdown now closes when using return key to select (#731)

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
---
 src/ftxui/component/dropdown.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/ftxui/component/dropdown.cpp b/src/ftxui/component/dropdown.cpp
index 235d9ae1..aa930db2 100644
--- a/src/ftxui/component/dropdown.cpp
+++ b/src/ftxui/component/dropdown.cpp
@@ -58,6 +58,24 @@ Component Dropdown(ConstStringListRef entries, int* selected) {
       });
     }
 
+    // Switch focus in between the checkbox and the radiobox when selecting it.
+    bool OnEvent(ftxui::Event event) override {
+      const bool show_old = show_;
+      const int selected_old = *selected_;
+      const bool handled = ComponentBase::OnEvent(event);
+
+      if (!show_old && show_) {
+        radiobox_->TakeFocus();
+      }
+
+      if (selected_old != *selected_) {
+        checkbox_->TakeFocus();
+        show_ = false;
+      }
+
+      return handled;
+    }
+
    private:
     ConstStringListRef entries_;
     bool show_ = false;
-- 
GitLab