Skip to content

Commit 6472313

Browse files
authored
Add a check in SearchChanged to skip manual item filtering when ItemCollection is used (#607)
1 parent 07a60d9 commit 6472313

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,10 +1083,13 @@ protected async Task SearchChanged(string? searchString)
10831083
{
10841084
_searchString = searchString;
10851085

1086-
var items = CollectAllMudListItems(true);
1087-
foreach (var item in items)
1086+
if (ItemCollection == null)
10881087
{
1089-
item.ApplySearch(IsMatch(item));
1088+
var items = CollectAllMudListItems(true);
1089+
foreach (var item in items)
1090+
{
1091+
item.ApplySearch(IsMatch(item));
1092+
}
10901093
}
10911094

10921095
await OnSearchStringChange.InvokeAsync(searchString);

tests/CodeBeam.MudBlazor.Extensions.UnitTests/Components/ListExtendedTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,5 +337,31 @@ public void ListColorTest(Color color)
337337
var listItemClasses = comp.Find(".mud-selected-item");
338338
listItemClasses.ClassList.Should().ContainInOrder(new[] { $"mud-{color.ToDescriptionString()}-text", $"mud-{color.ToDescriptionString()}-hover" });
339339
}
340+
341+
[Test]
342+
public async Task List_SearchChanged_WithNullItemCollection()
343+
{
344+
var comp = Context.Render<ListExperimentalSelectionTest>();
345+
var list = comp.FindComponent<MudListExtended<int>>().Instance;
346+
347+
// Verify ItemCollection is null - items are defined in markup
348+
list.ItemCollection.Should().BeNull();
349+
350+
// Verify initial items count from markup
351+
var initialItems = comp.FindAll("div.mud-list-item-extended").Count;
352+
initialItems.Should().Be(9); // 7 choices, 2 groups
353+
354+
// Verify we can access items via GetItems() - this calls CollectAllMudListItems internally
355+
var items = list.GetItems();
356+
items.Should().HaveCount(7);
357+
358+
// Select an item to verify the list still works correctly
359+
await comp.InvokeAsync(() => list.SelectedValue = 1);
360+
comp.WaitForAssertion(() => list.SelectedItem?.Text.Should().Be("Sparkling Water"));
361+
362+
// Verify all items are still accessible
363+
var finalItems = comp.FindAll("div.mud-list-item-extended").Count;
364+
finalItems.Should().Be(9);
365+
}
340366
}
341-
}
367+
}

0 commit comments

Comments
 (0)