diff --git a/frameworks/core/components_ng/pattern/grid/irregular/grid_irregular_filler.cpp b/frameworks/core/components_ng/pattern/grid/irregular/grid_irregular_filler.cpp index cd4da3710ac..349968bdb22 100644 --- a/frameworks/core/components_ng/pattern/grid/irregular/grid_irregular_filler.cpp +++ b/frameworks/core/components_ng/pattern/grid/irregular/grid_irregular_filler.cpp @@ -369,6 +369,7 @@ void GridIrregularFiller::SetItemInfo(int32_t idx, int32_t row, int32_t col, Gri props->UpdateCrossIndex(col); if (size.rows == 1 && size.columns == 1) { + pattern->ResetGridItemInfo(); return; } pattern->SetIrregularItemInfo({ .mainIndex = row, diff --git a/test/unittest/core/pattern/grid/grid_test_ng.cpp b/test/unittest/core/pattern/grid/grid_test_ng.cpp index 1e5d63fb5b2..e86a7b1ba66 100644 --- a/test/unittest/core/pattern/grid/grid_test_ng.cpp +++ b/test/unittest/core/pattern/grid/grid_test_ng.cpp @@ -124,6 +124,7 @@ GridItemModelNG GridTestNg::CreateGridItem(float width, float height, GridItemSt } else if (height != NULL_VALUE) { ViewAbstract::SetHeight(CalcLength(height)); } + ViewAbstract::SetFocusable(true); return itemModel; } diff --git a/test/unittest/core/pattern/grid/irregular/grid_layout_range_solver_test.cpp b/test/unittest/core/pattern/grid/irregular/grid_layout_range_solver_test.cpp index 5b7f65d0313..ffb788976e7 100644 --- a/test/unittest/core/pattern/grid/irregular/grid_layout_range_solver_test.cpp +++ b/test/unittest/core/pattern/grid/irregular/grid_layout_range_solver_test.cpp @@ -16,6 +16,7 @@ #include "irregular_matrices.h" #include "test/unittest/core/pattern/grid/grid_test_ng.h" +#include "core/components_ng/pattern/grid/grid_item_pattern.h" #include "core/components_ng/pattern/grid/irregular/grid_layout_range_solver.h" namespace OHOS::Ace::NG { @@ -734,4 +735,30 @@ HWTEST_F(GridLayoutRangeTest, ScrollEnabled001, TestSize.Level1) EXPECT_TRUE(pattern_->scrollable_); } } + +/** + * @tc.name: Focus001 + * @tc.desc: Test Grid changing focus + * @tc.type: FUNC + */ +HWTEST_F(GridLayoutRangeTest, Focus001, TestSize.Level1) +{ + auto model = CreateRepeatGrid(50, [](uint32_t idx) { return 200.0f; }); + model.SetColumnsTemplate("1fr 1fr 1fr"); + const auto options = GetOptionDemo14(); + model.SetLayoutOptions(options); + model.SetCachedCount(1); + CreateDone(); + for (int i = 0; i < 10; ++i) { + UpdateCurrentOffset(-200.0f); + for (int i = pattern_->info_.startIndex_; i <= pattern_->info_.endIndex_; ++i) { + bool hasInfo = GetChildPattern(frameNode_, i)->GetIrregularItemInfo().has_value(); + if (options.irregularIndexes.count(i)) { + EXPECT_TRUE(hasInfo); + } else { + EXPECT_FALSE(hasInfo); + } + } + } +} } // namespace OHOS::Ace::NG