Skip to content

Commit

Permalink
584 [HxAutosuggest] Stop propagation of Enter key event when selectin…
Browse files Browse the repository at this point in the history
…g an item - repro test
  • Loading branch information
hakenr committed Sep 25, 2023
1 parent 74921d9 commit 445cf80
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
8 changes: 7 additions & 1 deletion BlazorAppTest/BlazorAppTest.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand All @@ -21,4 +21,10 @@
<ProjectReference Include="..\Havit.SourceGenerators.StrongApiStringLocalizers\Havit.SourceGenerators.StrongApiStringLocalizers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Havit.Blazor.Components.Web.Bootstrap.Documentation\DemoData\**\*.*">
<Link>DemoData\%(RecursiveDir)%(FileName)%(Extension)</Link>
</Compile>
</ItemGroup>

</Project>
46 changes: 46 additions & 0 deletions BlazorAppTest/Pages/HxAutosuggest_Issue584_Test.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@page "/HxAutosuggest_Issue584_Test"
@using Havit.Blazor.Components.Web.Bootstrap.Documentation.DemoData;
@inject IDemoDataService DemoDataService

<EditForm Model="exampleModel" OnValidSubmit="HandleValidSubmit">
<HxAutosuggest Label="Employee"
Placeholder="Start typing to search by name"
TItem="EmployeeDto"
TValue="int?"
@bind-Value="@exampleModel.SelectedEmployeeId"
DataProvider="ProvideSuggestions"
MinimumLength="0"
ValueSelector="employee => employee.Id"
TextSelector="employee => employee.Name"
ItemFromValueResolver="ResolveAutosuggestItemFromValue">
<EmptyTemplate>
<span class="p-2">Couldn't find any matching employee</span>
</EmptyTemplate>
</HxAutosuggest>
<p class="mt-3">submitExecuted = @submitExecuted</p>
</EditForm>

@code {
private ExampleModel exampleModel = new();
private bool submitExecuted;
private void HandleValidSubmit()
{
submitExecuted = true;
}

private async Task<AutosuggestDataProviderResult<EmployeeDto>> ProvideSuggestions(AutosuggestDataProviderRequest request)
{
var matchingEmployees = await DemoDataService.FindEmployeesByNameAsync(request.UserInput, limitCount: 10, request.CancellationToken);
return new AutosuggestDataProviderResult<EmployeeDto> { Data = matchingEmployees };
}

private async Task<EmployeeDto> ResolveAutosuggestItemFromValue(int? value)
{
if (value is null)
{
return null;
}
return await DemoDataService.GetEmployeeByIdAsync(value.Value);
}
private record ExampleModel { public int? SelectedEmployeeId { get; set; } };
}
3 changes: 3 additions & 0 deletions BlazorAppTest/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Globalization;
using BlazorAppTest.Resources;
using Havit.Blazor.Components.Web;
using Havit.Blazor.Components.Web.Bootstrap.Documentation.DemoData;
using Havit.Blazor.GoogleTagManager;

namespace BlazorAppTest;
Expand Down Expand Up @@ -33,6 +34,8 @@ public void ConfigureServices(IServiceCollection services)
options.GtmId = "GTM-W2CT4P6"; // Havit.Blazor.GoogleTagManager DEV test
});

services.AddTransient<IDemoDataService, DemoDataService>();

// TESTs for Defaults
//HxAutosuggest.Defaults.InputSize = InputSize.Large;
//HxInputText.Defaults.InputSize = InputSize.Large;
Expand Down

0 comments on commit 445cf80

Please sign in to comment.