Dropdown now closes when using return key to select (#731)

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
mingsheng13 2023-08-19 11:02:04 +01:00 committed by GitHub
parent eb9a701fd7
commit 20baaef5b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;