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:
Arthur Sonzogni
2022-02-19 11:49:12 +01:00
committed by GitHub
parent f95ed885bb
commit 20f16b3984
5 changed files with 62 additions and 3 deletions

View File

@@ -305,6 +305,34 @@ TEST(ContainerTest, TakeFocus) {
EXPECT_FALSE(c23->Active());
}
TEST(ContainerTest, TabFocusable) {
int selected = 0;
auto c = Container::Tab(
{
Focusable(),
NonFocusable(),
Focusable(),
NonFocusable(),
},
&selected);
selected = 0;
EXPECT_TRUE(c->Focusable());
EXPECT_TRUE(c->Focused());
selected = 1;
EXPECT_FALSE(c->Focusable());
EXPECT_FALSE(c->Focused());
selected = 2;
EXPECT_TRUE(c->Focusable());
EXPECT_TRUE(c->Focused());
selected = 3;
EXPECT_FALSE(c->Focusable());
EXPECT_FALSE(c->Focused());
}
// 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.