I'm trying to use an event handler for the OnKeyUp event in my MudAutocomplete component, but after the event fires something triggers a redraw or similar that empties the text out of the Mudautocomplete component.
Here is my code:
<MudAutocomplete T="string" Label="Search" @bind-Value="value1" SearchFunc="@Search1"
OnKeyUp="test"/>
@code {
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 void test(KeyboardEventArgs e)
{
}
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));
}
}
You can test the code online here: https://try.mudblazor.com/snippet/QOGwkyEvyLeprkir
My end goal is to run a search from the text in the MudAutocomplete when a user presses enter, so I will eventually use OnKeyUp to detect the enter keypress