Skip to content

Commit

Permalink
feat(Select): add OnInputChangedCallback parameter (#3003)
Browse files Browse the repository at this point in the history
* feat(select): add OnInputChangedChallback parameter

* test: 更新单元测试

* chore: bump version 8.2.6-beta01
  • Loading branch information
ArgoZhang authored Feb 27, 2024
1 parent cc3ffc1 commit 1cdbe3e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.2.5</Version>
<Version>8.2.6-beta01</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
14 changes: 13 additions & 1 deletion src/BootstrapBlazor/Components/Select/Select.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ public partial class Select<TValue> : ISelect
[Parameter]
public bool IsEditable { get; set; }

/// <summary>
/// 获得/设置 选项输入更新后回调方法 默认 null
/// </summary>
/// <remarks>设置 <see cref="IsEditable"/> 后生效</remarks>
[Parameter]
public Func<string, Task>? OnInputChangedCallback { get; set; }

/// <summary>
/// 获得/设置 无搜索结果时显示文字
/// </summary>
Expand Down Expand Up @@ -436,7 +443,7 @@ private void OnClearValue()
CurrentValue = default;
}

private void OnChange(ChangeEventArgs args)
private async Task OnChange(ChangeEventArgs args)
{
if (args.Value is string v)
{
Expand All @@ -451,6 +458,11 @@ private void OnChange(ChangeEventArgs args)
Items = items;
}
CurrentValueAsString = v;

if (OnInputChangedCallback != null)
{
await OnInputChangedCallback(v);
}
}
}
}
7 changes: 7 additions & 0 deletions test/UnitTest/Components/SelectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,15 @@ public async Task IsEditable_Ok()
var input = cut.Find(".form-select");
Assert.True(input.IsReadOnly());

var updated = false;
cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.IsEditable, true);
pb.Add(a => a.OnInputChangedCallback, v =>
{
updated = true;
return Task.CompletedTask;
});
});
Assert.False(input.IsReadOnly());

Expand All @@ -828,5 +834,6 @@ await cut.InvokeAsync(() =>
input.Change("Test3");
});
Assert.Equal("Test3", cut.Instance.Value);
Assert.True(updated);
}
}

0 comments on commit 1cdbe3e

Please sign in to comment.