diff --git a/include/ftxui/component/toggle.hpp b/include/ftxui/component/toggle.hpp index 9747d6c..f0a2a65 100644 --- a/include/ftxui/component/toggle.hpp +++ b/include/ftxui/component/toggle.hpp @@ -27,7 +27,8 @@ class Toggle : public Component { // Callback. std::function on_change = []() {}; - + std::function on_enter = []() {}; + // Component implementation. Element Render() override; bool OnEvent(Event) override; diff --git a/src/ftxui/component/toggle.cpp b/src/ftxui/component/toggle.cpp index 16311d0..59786a2 100644 --- a/src/ftxui/component/toggle.cpp +++ b/src/ftxui/component/toggle.cpp @@ -40,10 +40,17 @@ bool Toggle::OnEvent(Event event) { selected = std::max(0, std::min(int(entries.size()) - 1, selected)); - if (old_selected != selected) + if (old_selected != selected) { on_change(); + return true; + } - return old_selected != selected; + if (event == Event::Return) { + on_enter(); + return true; + } + + return false; } } // namespace ftxui