forked from MudBlazor/MudBlazor
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autocomplete: Add MoreItemsTemplate RenderFragment. (MudBlazor#4566)
* Autocomplete: Add MoreItemsTemplate RenderFragment. * Fix unit test. * Always count returned items on search.
- Loading branch information
1 parent
e507fd6
commit 8cadb1d
Showing
4 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/MudBlazor.UnitTests.Viewer/TestComponents/Autocomplete/AutocompleteTest6.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@namespace MudBlazor.UnitTests.TestComponents | ||
<MudPopoverProvider></MudPopoverProvider> | ||
|
||
<MudAutocomplete T="string" Label="US States" @bind-Value="value1" SearchFunc="@Search1" MaxItems="10"> | ||
<MoreItemsTemplate> | ||
<MudText>Not all items are shown</MudText> | ||
</MoreItemsTemplate> | ||
</MudAutocomplete> | ||
|
||
@code { | ||
public static string __description__ = "There are more than 10 items, so the more items template should render"; | ||
|
||
private string value1; | ||
|
||
private string[] states = | ||
{ | ||
"Alabama", "Alaska", "American Samoa", "Arizona", | ||
"Arkansas", "California", "Colorado", "Connecticut", | ||
"Delaware", "District of Columbia", "Federated States of Micronesia", | ||
"Florida", "Georgia", "Guam", "Hawaii", "Idaho", | ||
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", | ||
"Louisiana", "Maine", "Marshall Islands", "Maryland", | ||
"Massachusetts", "Michigan", "Minnesota", "Mississippi", | ||
"Missouri", "Montana", "Nebraska", "Nevada", | ||
"New Hampshire", "New Jersey", "New Mexico", "New York", | ||
"North Carolina", "North Dakota", "Northern Mariana Islands", "Ohio", | ||
"Oklahoma", "Oregon", "Palau", "Pennsylvania", "Puerto Rico", | ||
"Rhode Island", "South Carolina", "South Dakota", "Tennessee", | ||
"Texas", "Utah", "Vermont", "Virgin Island", "Virginia", | ||
"Washington", "West Virginia", "Wisconsin", "Wyoming", | ||
}; | ||
|
||
private async Task<IEnumerable<string>> Search1(string value) | ||
{ | ||
// In real life use an asynchronous function for fetching data from an api. | ||
await Task.Delay(5); | ||
|
||
// if text is null or empty, show complete list | ||
if (string.IsNullOrEmpty(value)) | ||
return states; | ||
return states.Where(x => x.Contains(value, StringComparison.InvariantCultureIgnoreCase)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters