mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
Improve ComponentBase and Container::Tab Focusable implementations (#341)
- Provide better defaults for ComponentBase `Focusable()` and `ActiveChild()` methods. This resolves: https://github.com/ArthurSonzogni/FTXUI/issues/335 - Implement `Container::Tab` 's `Focusable()` methods. This prevents the users to navigate into a tab with no interactivity.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access, allocator, make_shared
|
||||
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Make
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
|
||||
#include "gtest/gtest_pred_impl.h" // for EXPECT_EQ, Test, SuiteApiResolver, TEST, TestFactoryImpl
|
||||
|
||||
@@ -155,6 +156,22 @@ TEST(ContainerTest, ChildAt) {
|
||||
EXPECT_EQ(parent->ChildAt(0u), child_2);
|
||||
}
|
||||
|
||||
TEST(ComponentTest, NonFocusableAreNotFocused) {
|
||||
class NonFocusable : public ComponentBase {
|
||||
bool Focusable() const override { return false; }
|
||||
};
|
||||
auto root = Make<NonFocusable>();
|
||||
EXPECT_FALSE(root->Focused());
|
||||
EXPECT_EQ(root->ActiveChild(), nullptr);
|
||||
|
||||
auto child = Make<NonFocusable>();
|
||||
root->Add(child);
|
||||
EXPECT_FALSE(root->Focused());
|
||||
EXPECT_FALSE(child->Focused());
|
||||
EXPECT_EQ(root->ActiveChild(), nullptr);
|
||||
EXPECT_EQ(child->ActiveChild(), nullptr);
|
||||
}
|
||||
|
||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
|
Reference in New Issue
Block a user